> On Aug 18, 2017, at 2:28 AM, Sam Waxman <samwax...@gmail.com> wrote:
> 
> If I have code like this,
> 
> (define-syntax-rule (identity x)
>   x)
> 
> ((identity identity) 1)
> 
> Is there a simple way to change this so that ((identity identity) 1) actually 
> does expand into (identity 1) which expands into 1? I'm guessing not, but it 
> would certainly be a nice trick if there were.


You need an "identifier macro", which is a macro that will match the case where 
the macro name is used in an identifier position. [1] For instance: 

#lang racket
(require rackunit)

(define-syntax (identity stx)
  (syntax-case stx ()
    [(identity arg) #'(#%app identity arg)]
    [identity (identifier? #'identity) ; guard prevents matching `(identity)`
     #'(λ (x) x)]))

(check-true (procedure? identity))
(check-equal? ((identity identity) 1) 1)
(check-equal? (map identity (range 5)) (range 5))




[1] 
http://docs.racket-lang.org/guide/pattern-macros.html?q=identifier%20macro#%28tech._identifier._macro%29
 
<http://docs.racket-lang.org/guide/pattern-macros.html?q=identifier%20macro#(tech._identifier._macro)>

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