> On Aug 18, 2017, at 6:41 PM, Matthew Butterick <m...@mbtype.com> wrote:
> 
> 
>> On Aug 18, 2017, at 2:28 AM, Sam Waxman <samwax...@gmail.com 
>> <mailto: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)]))



That is guaranteed to evaluate the expression. What if you really want to 
insert a macro that takes apart/suspends/deletes the outer expression? (A 
2-clause ‘identity’ might appear to be able to do so.) 

The point of “macro expansion won’t re-focus outside of the given expression” 
stands. 

— Matthias





> 
> (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 
> <mailto:racket-users+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

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