Reputation:
I am confused by the documentation about the usage syntax-case, but what can f
possibly mean?
(define-syntax (check stx)
(syntax-case stx ()
[(f (x y))
#'(list 'second: f x y)]))
Upvotes: 0
Views: 280
Reputation: 17203
This code is broken in a fairly subtle way.
To begin with,
(define-syntax (check stx)
(syntax-case stx ()
[(f (x y))
#'(list 'second: f x y)]))
(check (3 4))
Yields an error: check: bad syntax in: check
The problem, though, is the use of 'f' that appears in the expansion. To see this, try taking it out:
(define-syntax (check stx)
(syntax-case stx ()
[(f (x y))
#'(list 'second: 1234 x y)]))
(check (3 4))
This evaluates fine, producing '(second: 1234 3 4)
So, why does the first one fail? The problem is that in your first example,
(check (3 4))
expands into
(list 'second check 3 4)
The problem with this, though, is that the 'check' in the expansion is another use of the 'check' macro, and must therefore be further expanded, and this second expansion does not have the right shape.
To see this, you can try expanding your program using the macro stepper. Run the macro stepper, use the pull-down menu to select "Standard" macro hiding, click on the "End-->" button, and then go back one step.
The normal convention is to use the underscore "_" as a "don't care" symbol to match against the name of the macro in the pattern, like this:
(define-syntax (check stx)
(syntax-case stx ()
[(_ (x y))
#'(list 'second: 1234 x y)]))
(check (3 4))
Out of curiosity: where does this code come from?
Upvotes: 1