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

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Sat Aug 25 13:33:43 EDT 2012

On 08/25/2012 01:08 PM, Neil Toronto wrote:
> On 08/25/2012 10:53 AM, Ryan Culpepper wrote:
>> On 08/25/2012 12:19 PM, Neil Toronto wrote:
>> I've reordered these a bit:
>>> number
>>> string
>>> bytes
>>> character
>>> regexp
>> In other words, "literal data". But did you check that the '#%datum'
>> macro associated with them has the standard meaning? If not, they could
>> expand into arbitrary expressions (possibly with side effects)!
> 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)

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.


Posted on the dev mailing list.