> On Sep 4, 2015, at 4:26 AM, Konrad Hinsen <konrad.hin...@fastmail.net> wrote:
> 
> Brian Mastenbrook writes:
> 
>> It's a capture problem. In the first case, you're just binding the
>> name "send" locally and all is well. In the second case, you're
>> trying to introduce a binding for "send" that you didn't get from
>> the input form.
> 
> Ahhh.... that one has bitten me before, but I had forgotten about it.
> Thanks for the reminder!
> 
>> You're also getting a confusing error because "send" is already
>> bound; try using a name that's not already defined and you should
>> get an unbound identifier.
> 
> I used a bound symbol intentionally to see if I can shadow an existing
> syntax transformer binding.

Ok, if you *really* want to shadow an existing binding, you can use 
datum->syntax, but using a syntax parameter is much better:
(define-syntax (def stx)
  (syntax-parse stx
    [(_ (fn-name:id arg:id ...) body ... )
     #:with send-id (datum->syntax #'fn-name 'send)
     #'(define (fn-name arg ...)
         (let-syntax ([send-id (λ (stx)
                                 (syntax-parse stx
                                   [(send-id obj:expr method:id x:expr (... 
...))
                                    #'(method obj x (... ...))]))])
           body ...))]))

>> Alternatively, you can use a syntax parameter, which is probably
>> the ideal solution here.
> 
> At least it's one that works. It feels like cheating to use dynamic
> scoping to get around a problem with lexical scoping, but knowing when
> to cheat is a fundamental competence when dealing with any bureaucracy ;-)

Um, the reason a syntax parameter is better is that it *does* follow the 
lexical scoping rules, where the unhygienic version does weird things you 
wouldn't expect. Using datum->syntax is cheating a lot more, and syntax 
parameters deal with problems like this in a much better way.

P.S.
Have you read Fear of Macros? If you haven't, I highly recommend it because 
it's awesome.

> Thanks again,
>  Konrad.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to