On Tuesday, January 10, 2017 at 4:34:41 PM UTC-5, Alexis King wrote:
> Basically, the difference is as follows: #:literals compares
> identifiers using free-identifier=?, but #:datum-literals compares
> them by using syntax-e and eq?.
> 
> You can observe the difference using two extremely simple macros
> that only differ in their use of #:literals or #:datum-literals:
> 
>   (define-syntax lit
>     (syntax-parser
>       #:literals [add1]
>       [(_ add1) #'"add1"]
>       [(_ _)    #'"something else"]))
> 
>   (define-syntax dat
>     (syntax-parser
>       #:datum-literals [add1]
>       [(_ add1) #'"add1"]
>       [(_ _)    #'"something else"]))
> 
> Observe the behavior of the `lit` macro:
> 
>   > (lit add1)
>   "add1"
>   > (let ([add1 #f])
>       (lit add1))
>   "something else"
>   > (require (rename-in racket/base [add1 my-add1]))
>   > (lit my-add1)
>   "add1"
> 
> Contrast the results with the same examples using the `dat` macro
> instead:
> 
>   > (dat add1)
>   "add1"
>   > (let ([add1 #f])
>       (dat add1))
>   "add1"
>   > (require (rename-in racket/base [add1 my-add1]))
>   > (dat my-add1)
>   "something else"
> 
> By “recognize symbolically”, it means that #:datum-literals looks
> at the name of the symbol and nothing else. In contrast, #:literals
> is more advanced, since it looks for an identifier with the same
> binding as the one specified.
> 
> In my opinion, when in doubt, prefer #:literals.
> 
> > On Jan 10, 2017, at 11:58 AM, Deren Dohoda
> > wrote:
> > 
> > I am still making most macros using syntax-rules and syntax-case
> > because when I happened to learn macros these were the paths of
> > least resistance. Every once in a while I try to learn a little
> > more of syntax-parse since the few times I've tried it I really
> > liked it.
> > 
> > It appears that, in general, syntax-rules and syntax-case use what
> > syntax-parse considers "datum-literals", which the docs say are
> > recognized "symbolically" versus actual literals which are recognized
> > "by binding." The example in the documents for some reason clarifies
> > nothing since both expressions are the same and give the same output,
> > making this a distinction without an obvious difference.
> > 
> > Can someone explain the intention behind #:literals as opposed to
> > #:datum-literals? In what cases should I consider #:literals? Why
> > would I want to avoid #:datum-literals, or vice versa?
> > 
> > Thanks,
> > Deren

I have a related question: How does #:literals differ from ~literal in the 
left-hand side of syntax-parse? I used to think they were the same but it seems 
that changing from one to another altered my program's behavior...

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to