I'd like to introduce bindings in a macro. The commented code for with-my-struct is more what I would like to see, but it doesn't work, The uncommented code works, but is more complex and, well, uglier. Is there a clearer way (i.e. closer to the commented code) to write it? <br>
<br>(module dummy mzscheme<br> <br> (provide (all-defined))<br> <br> (define-struct my-struct (a b c))<br> <br>; (define-syntax with-my-struct<br>; (syntax-rules ()<br>; ((with-my-struct s<br>; expr ...)<br>
; (let ((a (my-struct-a s))<br>; (b (my-struct-b s))<br>; (c (my-struct-c s)))<br>; expr ...))))<br> <br> (define-syntax (with-my-struct stx)<br> (syntax-case stx ()<br> ((with-my-struct s<br>
expr ...)<br> (with-syntax ((a (datum->syntax-object (syntax with-my-struct) 'a))<br> (b (datum->syntax-object (syntax with-my-struct) 'b))<br> (c (datum->syntax-object (syntax with-my-struct) 'c)))<br>
(syntax<br> (let ((a (my-struct-a s))<br> (b (my-struct-b s))<br> (c (my-struct-c s)))<br> expr ...))))))<br><br> <br> (define (test-with-my-struct)<br> (let ((s (make-my-struct 1 2 3)))<br>
(with-my-struct s<br> (printf "a = ~a, b = ~a, c = ~a~n" a b c))))<br> <br> (test-with-my-struct)<br> <br> )<br><br>Thanks,<br>Doug<br>