<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Thanks, using syntax->list solved the problem. </div><br><div><div>On Apr 17, 2014, at 12:22 AM, Carl Eastlund <<a href="mailto:carl.eastlund@gmail.com">carl.eastlund@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div><div>Syntax objects are a rather complex data type, especially where pairs and lists are involved. Essentially, a syntax object containing a list can be broken up with extra syntax nodes at all, some, or none of its intermediate conses, depending on how it is constructed. For example, if you just write #'(1 2 3), there will be one syntax node at the top level and none anywhere else. If you write #'(1 . (2 . (3 . ()))) instead, you get syntax nodes at each step along the way. The syntax objects differ, even though '(1 2 3) and '(1 . (2 . (3 . ()))) produce the same value.<br>
<br></div>So what happened in your program? Well, when you define f2 using proc-with-stx, the define-syntax-rule from proc-with-stx substitutes (lambda (x) #f) in for expr, and your syntax object is therefore [essentially] #'(lambda (x) #f). It's a straightforward list, one syntax node at the top level.<br>
<br>When you define f using lambda-with-stx, however, the define-syntax-rule for lambda-with-stx has to substitute (x) for args and #f for body ... in (lambda args body ...). I'm guessing the result comes out something like (lambda . ((x) . (#f . ()))); the process may just automatically put a syntax node at each cons. Then proc-with-stx substitutes that for expr, and you get [essentially] #'(lambda . ((x) . (#f . ()))).<br>
<br></div>Basically, you can't rely on where syntax-e will split up a list into syntax objects unless you constructed it yourself. If you want predictable results, use syntax->list or syntax->datum.<br></div><div class="gmail_extra">
<br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Wed, Apr 16, 2014 at 10:33 PM, Alexander D. Knauth <span dir="ltr"><<a href="mailto:alexander@knauth.org" target="_blank">alexander@knauth.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Basically, I have a macro, called proc-with-stx, that captures an expression and stores it in a syntax object, and I have another macro, called lambda-with-stx, that expands to (proc-with-stx (lambda …)).<br>
When I use (proc-with-stx (lambda (x) #f), then the syntax-e of the syntax-object is a list, but when I use (lambda-with-stx (x) #f), which should expand to the same thing, the syntax-e of the syntax-object is a non-list pair:<br>
<br>
#lang racket<br>
<br>
(module+ test<br>
(require rackunit))<br>
<br>
(struct proc+stx (proc stx)<br>
#:property prop:procedure (struct-field-index proc))<br>
<br>
(define-syntax-rule (proc-with-stx expr)<br>
(proc+stx expr #'expr))<br>
<br>
(define-syntax-rule (lambda-with-stx args body ...)<br>
(proc-with-stx (lambda args body ...)))<br>
<br>
(module+ test<br>
(define f<br>
(lambda-with-stx (x) #f))<br>
(define f2 ; f should expand to f2<br>
(proc-with-stx (lambda (x) #f)))<br>
<br>
(define f-stx (proc+stx-stx f))<br>
(define f2-stx (proc+stx-stx f2))<br>
<br>
;; tests for f:<br>
(check-true (procedure? f))<br>
(check-equal? (f 1) #f)<br>
(check-pred list? (syntax-e f-stx)) ; this test fails, produces '(#<syntax lambda> #<syntax (x)> . #<syntax (#f)>) instead<br>
;; same tests for f2<br>
(check-true (procedure? f2))<br>
(check-equal? (f2 1) #f)<br>
(check-pred list? (syntax-e f2-stx)) ; this test passes, produces '(#<syntax lambda> #<syntax (x)> #<syntax #f>)<br>
)<br>
<br>
Why doesn't (syntax-e f-stx) produce a list like (syntax-e f2stx) does?<br>
<br>
<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</blockquote></div><br></div>
</blockquote></div><br></body></html>