[racket] macro question
On 10/02/2014 09:19 PM, Kevin Forchione wrote:
> Hi guys,
> Why does this appear to work? I assume it’s not a recommended approach.
>
> #lang racket
>
> (require (for-syntax syntax/parse))
>
> (define-syntax (mylet stx)
> (let ([val (syntax-case stx ()
> [(_ x) #'x]
> [(_ x xs ...) #'(cons x (mylet xs ...))])])
> val))
>
> (mylet 1 2 3) => ‘(1 2 3)
It doesn't return '(1 2 3); it returns '(1 2 . 3).
Other than that, the let is unnecessary, but it's just a straightforward
recursive macro.
Maybe the answer to your question is that syntax-case is nothing
special; it's basically a version of match specialized to dealing with
syntax objects. You can use it inside of other expressions. See
http://www.greghendershott.com/fear-of-macros/ for an explanation of how
not-special syntax-case is.
Ryan