2017-08-01 20:11 GMT+02:00 Jordan Johnson <j...@fellowhuman.com>:

> Hi all,
>
> Reading the documentation on ~datum in syntax/parse, I see:
>
> The ~datum form is useful for recognizing identifiers symbolically, in
> contrast to the ~literal form, which recognizes them by binding.
> That makes sense to me. But then I see:
>
> > (syntax-parse (let
> <http://../reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29>
>  ([define
> <http://../reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29>
>  'something-else]) #'(define
> <http://../reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29>
>  x y))
>     [((~datum define
> <http://../reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29>
> ) var:id e:expr) 'yes]
>     [_
> <http://../reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29>
>  'no])
>
> 'yes
> > (syntax-parse (let
> <http://../reference/let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29>
>  ([define
> <http://../reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29>
>  'something-else]) #'(define
> <http://../reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29>
>  x y))
>     [((~literal define
> <http://../reference/define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29>
> ) var:id e:expr) 'yes]
>     [_
> <http://../reference/stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29.__%29%29>
>  'no])
>
> 'yes
>
> I’m confused by this. It seems, based on the first sentence I quoted, that
> in the second example, in which the syntax being parsed has *define* bound
> to something other than the usual, the use of *~literal* should make the
> first clause fail to match. And I’d have expected the examples to contrast
> *~datum* and *~literal*, rather than exhibit the same behavior.
>

The binding information is attached a syntax object during expansion.
In your example the #'(define x y) haven't gone through expansion,
so you do not get what your expected result.

However we can change your macro a little:


#lang racket
(require (for-syntax syntax/parse))

(define-syntax (is-define? stx)
  (syntax-parse stx
    [(_is-define? id)
     (syntax-parse #'id
       [(~literal define) #''yes]
       [_                 #''no])]))

(is-define? define)

(let ([define 42])
  (is-define? define))

This will result in

'yes
'no


/Jens Axel

-- 
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