rntz
2022-5-23 18:33:46

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


rntz
2022-5-23 18:34:01

e.g. something like a “hygienic quasiquote”


rntz
2022-5-23 18:34:27

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


samth
2022-5-23 18:35:42

See make-syntax-introducer


rntz
2022-5-23 18:38:32

thanks


rntz
2022-5-23 18:38:38

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


samth
2022-5-23 18:39:57

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


samth
2022-5-23 18:40:37

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


rntz
2022-5-23 18:44:38

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


rntz
2022-5-23 18:45:35

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


rntz
2022-5-23 18:45:56

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


soegaard2
2022-5-23 19:25:01

Apropos, here is how it looks like in Urlang:


sorawee
2022-5-23 19:26:28

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


soegaard2
2022-5-23 19:32:36

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>


rntz
2022-5-23 19:52:56

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


rntz
2022-5-23 19:53:13

thanks @soegaard2 @samth


rntz
2022-5-23 22:27:35

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


rntz
2022-5-23 22:28:31

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:


soegaard2
2022-5-24 06:41:07

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