
is there any way to get Racket to apply hygiene to a piece of syntax it being a macro?

e.g. something like a “hygienic quasiquote”

I am generating syntax in a little compiler I am writing and it would be handy to have Racket handle the hygiene for me

See make-syntax-introducer

thanks

I guess I need to go understand scope sets now, though :stuck_out_tongue:

Basically you’d call it before and after each transformation.

Or you could just apply it on each quasiquote, I think that would be something like what you want.

I think I’ve just realized that I don’t need hygiene because in this case I’m only dealing with closed terms

I have also discovered that ((lambda (γ) (lambda (x) ((lambda (x) (cdr ((lambda (x) x) x))) (cons γ x)))) '())
is a very strange way to write the identity function

(this is my compiler’s output on (lambda (x) x)
)

Apropos, here is how it looks like in Urlang:

If you have transform
as a procedure, you can use syntax-local-apply-transformer
too, I think?

The code transformed is Urlang not Racket, so I need to roll my own. For one, I don’t use the same expansion contexts as syntax-local-apply-transformer
expects.
<https://github.com/soegaard/urlang/blob/master/urlang/main.rkt#L966>

ok, turns out to get my compiler to emit simpler code I will need to use open terms. currently using gensym
and the identity function becomes ((lambda (env122243) (lambda (x122244) (cdr (cons env122243 x122244)))) '())
. with hygiene that could look a lot nicer :P

thanks @soegaard2 @samth

hm, ok. I have it working, I think. is there a way to pretty-print syntax objects that disambiguates false shadowing created by hygiene?

it behaves correctly under eval, but when displayed I just have a lot of variables named x
and don’t know which is which :joy:

@rntz In DrRacket a syntax object prints as a “snip” with a triangle. Clicking an identifier highlights the other identifiers with the same marks.