Hi all - <br><br>is it possible to create an complex object during syntax expansion but return it as the result of the expansion? It is possible to do so for basic types such as numbers.<br><br>(module add mzscheme <br> (define (add a b) (+ a b))
<br> (provide (all-defined)))<br>(require add)<br>(require-for-syntax add)<br>(define-syntax (macro-add stx)<br> (syntax-case stx () <br> ((_ a b)<br> (with-syntax ((val (datum->syntax-object <br> #'_
<br> (add (syntax-object->datum #'a)<br> (syntax-object->datum #'b)))))<br> #'val))))<br>(= (add 5 6) (macro-add 5 6)) ; => #t ; as both returns 11.
<br><br>But this does not hold for complex object such as struct with the following code - is this something wrong with the code or is it something else? <br><br>(module foo mzscheme<br> (define-struct foo (vals))<br> (define (create-foo vals)
<br> (make-foo vals))<br> (provide (all-defined)))<br>(require foo)<br>(require-for-syntax foo)<br>(define-syntax (macro-foo stx)<br> (syntax-case stx () <br> ((_ val1 val2 ...)<br> (with-syntax ((foo (datum->syntax-object
<br> #'_ <br> (create-foo (syntax->list #'(val1 val2 ...))))))<br> #'foo))))<br>(define f1 (macro-foo 1 2 3))<br>f1 ; => shows #<struct:foo><br>
(foo? f1) ; => #f <br>(foo-vals f1) ; => error: foo-vals: expects args of type <struct:foo>; given instance of a different <struct:foo><br><br>Any insights are appreciated, thanks,<br>yc<br><br>