[racket] macro question
On Oct 2, 2014, at 6:53 PM, Ryan Culpepper <ryanc at ccs.neu.edu> wrote:
> 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. Seehttp://www.greghendershott.com/fear-of-macros/ for an explanation of how not-special syntax-case is.
Sorry about the typo. Yes, ‘(1 2 . 3). I was surprised that wrapping a let around the syntax-case worked. But I suppose that define-syntax behaves similarly to define? In other words I could have any number expressions within the body of the define-syntax, manipulating syntax objects?
-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141002/930d19a5/attachment.html>