[racket-dev] When is it safe to not rename a runtime value in a macro?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Sat Aug 25 13:57:00 EDT 2012

On 08/25/2012 11:33 AM, Ryan Culpepper wrote:
> On 08/25/2012 01:08 PM, Neil Toronto wrote:
>> A number can expand to an arbitrary expression? How?
>>
>> And what do you mean by "the '#%datum' macro associated with them"?
>> Applied to them?
>
>  > (let-syntax ([#%datum (lambda (stx) #'(printf "hello\n"))]) 5)
> hello
>
> In Racket, literal data carry lexical information just like identifiers.
> When a literal datum is used as an expression, the macro expander
> synthesizes a '#%datum' identifier that determines what to do with the
> literal. The Racket '#%datum' macro just expands into a 'quote'
> expression if the datum is not a keyword.
>
> The implicit '#%app' syntax works similarly, except it takes its lexical
> context from the pair that represents the application.

Holy heck I had no idea. That's awesome and scary.

So this is what I have now:

(define skip-ids
   (syntax->list #'(+ - * / < > <= >= = min max)))

(define (skip-binding? e-stx)
   (let ([e-stx  (local-expand e-stx 'expression #f)])
     (and (identifier? e-stx)
          (findf (λ (skip-id) (free-identifier=? skip-id e-stx))
                 skip-ids))))


I would have called it safe before today, but I knew fewer awesome and 
scary things. Does it look safe to you?

Neil ⊥


Posted on the dev mailing list.