The ~datum form is useful for recognizing identifiers symbolically, in contrast to the ~literal form, which recognizes them by binding.
| |||
'yes | |||
| |||
'yes |
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...
(define-syntax (is-define? stx)(syntax-parse stx[(_is-define? id)(syntax-parse #'id[(~literal define) #''yes]
[(~datum define) #''not-really][_ #''not-even-close])]))(is-define? define) ;; 'yes
(let ([define 42])
(is-define? define)) ;; 'not-really(is-define? something-else) ;; 'not-even-close