Hello!
In a simple example, I saw a weird or unexpected (from me) behaviour from the c-lambda function. Here is what I did:
(c-declare "#include <stdio.h>") ((c-lambda () void "printf("test: %d\n", 10);")
This worked just fine, but if I do:
(c-declare "#include <stdio.h>") ((c-lambda () void (string-append "printf("%d\n"," "10);"))
I get:
*** ERROR IN "/home/dave/temp/test.scm"@4.11 -- Third argument to 'c-lambda' must be a string
Why is that the c-lambda cannot or does not evaluate its arguments? Is this occuring because c-lambda is a macro?
I'd like it to evaluate my (string-append ...) because then, I could simplify the usage of the ffi with macros...
Thanks!
David
Afficher les réponses par date
On 26-Mar-08, at 3:55 PM, David St-Hilaire wrote:
Hello!
In a simple example, I saw a weird or unexpected (from me) behaviour from the c-lambda function. Here is what I did:
(c-declare "#include <stdio.h>") ((c-lambda () void "printf("test: %d\n", 10);")
This worked just fine, but if I do:
(c-declare "#include <stdio.h>") ((c-lambda () void (string-append "printf("%d\n"," "10);"))
I get:
*** ERROR IN "/home/dave/temp/test.scm"@4.11 -- Third argument to 'c- lambda' must be a string
Why is that the c-lambda cannot or does not evaluate its arguments? Is this occuring because c-lambda is a macro?
I'd like it to evaluate my (string-append ...) because then, I could simplify the usage of the ffi with macros...
The call to string-append must happen at macro-expansion time, so that the compiler sees the result of the string-append inside the c-lambda form. So you have to use a macro to achieve this. A quick-and-dirty example:
(define-macro (my-c-lambda param-types result-type body) `(c-lambda ,param-types ,result-type ,(eval body)))
or
(define-macro (c-lambda param-types result-type body) `(##c-lambda ,param-types ,result-type ,(eval body)))
Marc