]]>

add is not included so you get an error.

You can tell by just type inn identifiers in the interactions window before you define them and like sqrt you'll see #<procedure:sqrt> with sqrt replaced by something else.

The reason for this is unknown but I imagine it has to do with sqrt being a standard procedure in RNRS Scheme and Racket. If the package is based on one R5RS (the closest language to R3RS which were used in SICP) you will have all of the R5RS procedure and syntax that are not in direct violation of R3RS.

Statistics: Posted by sylwester — Mon Apr 21, 2014 1:44 pm

]]>

- Code:
`(defstruct (cvmatrix (:constructor %make-cvmatrix))`

(sap (mat) :type sb-sys:system-area-pointer :read-only t))

(defun make-cvmatrix ()

(let* ((matrix (%make-cvmatrix))

(sap (cvmatrix-sap matrix)))

(tg:finalize matrix (lambda (x) (del-mat sap)))

matrix))

When I run the make-cvmatrix function to create a matrix it outputs a struct instead of a pointer like i needed. I changed the last line of the make-cvmatrix function to be "sap" as below:

- Code:
`(tg:finalize matrix (lambda (x) (del-mat sap)))`

sap))

...and it appears to run fine with only minor variations in my ram levels which i suppose is just a result of lisps GC in process.

Since I'm new to GC w/ trivial-garbage, I was hoping someone can verify first that the change to sap was an ok move.

I was hoping someone could edit my code so I have a good example of Lisp GC with TG to work from and if I write a defcfun for this C wrapper :

- Code:
`Mat* cv_create_Mat_typed(int rows, int cols, int type) {`

return new Mat(rows, cols, type);

}

eg:

(defcfun ("cv_create_Mat_typed" mat-typed) (:pointer mat)

"MAT constructor with a row, column and type parameter."

(rows :int)

(cols :int)

(type :int))

show me where the rows cols type params get placed in an edited finalizer/constructor above..I would definately appreciate greatly:), concrete examples using the code I posted.

Statistics: Posted by joeish80829 — Sun Apr 20, 2014 4:53 am

]]>

Statistics: Posted by macrolyte — Thu Apr 17, 2014 11:26 am

]]>

The following codes are from the book and I use the procedure "sqrt" at beginning:

- Code:
`(sqrt (+ 100 37))`

(define (sqrt-iter guess x)

(if (good-enougth? guess x)

guess

(sqrt-iter (improve guess x)

x)))

(define (improve guess x)

(average guess (/ x guess)))

(define (average x y)

(/ (+ x y) 2))

(define (good-enougth? guess x)

(< (abs (- (square guess) x)) 0.001))

(define (square x)

(* x x))

(define (sqrt x)

(sqrt-iter 1.0 x))

It worked perfactly well. But as for my understanding, you have to define a procedure before use it, right? So I don't understand how this can work?

And I do an experiment:

- Code:
`(add 2 2)`

(define (add x y)

(test x y))

(define (test x y)

(+ x y))

But this time the interpreter gave me "add: undefined; cannot reference undefined identifier", so I am totally confused about these results, can somebody explain what's going to me?

Thank you

Statistics: Posted by blackdiz — Wed Apr 16, 2014 5:50 pm

]]>

]]>

function wraps(not shown). I was told by someone at cffi-devel that

" You use sb-sys:system-area-pointer as type, and this will tie you to

SBCL. There is no reason for that.

"

How would I change the sb-sys:system-area-pointer type in the below code to make it

compatible with all implementations. I could use a concrete example based on the

below code since I'm still kind of new to this part of CFFI.Thanks in advance for

any help on this

- Code:
`(defstruct (cvmatrix (:constructor %make-cvmatrix))`

(sap (%mat) :type sb-sys:system-area-pointer :read-only t))

(defun make-cvmatrix (&optional enable-finalizer)

(let* ((matrix (%make-cvmatrix))

(sap (cvmatrix-sap matrix)))

(when enable-finalizer

(tg:finalize matrix (lambda () (del-mat sap))))

sap))

Statistics: Posted by joeish80829 — Sun Apr 13, 2014 8:39 am

]]>

How do I update the finalizer below to be for the mat-data defcfun at the

bottom of the page. So where do I put the rows cols params, there seems

to be no place for them in the defstruct wwhere %mat is called. Any

help is appreciated

- Code:

(defstruct (cvmatrix (:constructor %make-cvmatrix))

(sap (%mat) :type sb-sys:system-area-pointer :read-only t))

(defun make-cvmatrix (&optional enable-finalizer)

(let* ((matrix (%make-cvmatrix))

(sap (cvmatrix-sap matrix)))

(when enable-finalizer

(tg:finalize matrix (lambda () (del-mat sap))))

sap))

(defcfun ("cv_create_Mat" %mat) (:pointer mat)

"MAT constructor")

;; Mat::Mat(int rows, int cols, int type, void* data)

;; Mat* cv_create_Mat_with_data(int rows, int cols, int type, void* data)

(defcfun ("cv_create_Mat_with_data" mat-data) (:pointer mat)

(rows :int)

(cols :int)

(type :int)

(data :pointer))

Statistics: Posted by joeish80829 — Sun Apr 13, 2014 7:19 am

]]>

- Code:
`;;double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray())`

;;double cv_norm(Mat* src1, int normType, Mat* mask)

(defcfun ("cv_norm" %norm0) :void

(src1 (:pointer mat))

(norm-type :int)

(mask (:pointer mat)))

(defun norm0 (src1 &optional (norm-type +norm-l2+) (mask (mat)))

(%norm0 src1 norm-type mask))

;;double norm(InputArray src1, InputArray src2, int normType=NORM_L2, InputArray mask=noArray())

;;double cv_norm4(Mat* src1, Mat* src2, int normType, Mat* mask)

(defcfun ("cv_norm4" %norm4) :void

(src1 (:pointer mat))

(src2 (:pointer mat))

(norm-type :int)

(mask (:pointer mat)))

(defun norm4 (src1 src2 &optional (norm-type +norm-l2+) (mask (mat)))

(%norm4 src1 src2 norm-type mask))

(defun norm (&optional arg1 arg2 ar3 arg4)

(cond ((numberp arg2)

(norm0 arg1 arg2 arg3))

((...)

(norm4 ...))

(t nil)))

Statistics: Posted by joeish80829 — Sat Apr 12, 2014 5:22 pm

]]>

Lisp Machine Manual wrote:

(values . values) or (:return-list . values)

Records values as the return values list of the function, to be used if anyone asks what values it returns. This is purely documentation.

Statistics: Posted by edgar-rft — Sat Apr 12, 2014 5:37 am

]]>