laurent.orseau
2020-4-18 09:34:25

Racket has many macros that introduce new ids (which is not hygienic), such as struct.


jesse
2020-4-18 14:28:55

this may sound really dumb and I ought to know better, but why is a macro that introduces ids non-hygenic? It seems OK to me to have a macro that expands to, say, a define. By my lights, that’s introducing an identifier. But perhaps I’m not looking at the situation in the right way.


greg
2020-4-18 14:44:41

In the define example the identifier is supplied by the user, and that — and only that — gets introduced.


greg
2020-4-18 14:44:48

(let ([foo-bar 42]) (struct foo (bar)) (+ foo-bar 1))


greg
2020-4-18 14:45:29

Here the struct macro introduces a foo-bar that shadows the one apparent in the code.


jesse
2020-4-18 14:46:30

thanks, that helps


greg
2020-4-18 14:46:32

I think everyone would agree that it would be horribly tedious if you had to supply all the accessor names and the predicate when you invoke struct.


jesse
2020-4-18 14:46:46

agreed


greg
2020-4-18 14:46:56

And hopefully it’s not surprising because people know struct.


jesse
2020-4-18 14:47:29

but to my mind, all those things are still functions of the data I gave to struct; it’s as though there are lots of format-ids being done, not just a simple define


greg
2020-4-18 14:47:35

But strictly speaking, it’s “surprising” in the way that non-hygienic macros can be surprising in bad ways.


jesse
2020-4-18 14:48:04

your let example is really illuminating


greg
2020-4-18 14:48:07

Yes, it definitely helps that the identifiers are created using a prefix that you supply.


jesse
2020-4-18 14:48:20

it shows how there’s a kind of “polluting” going on by struct that wouldn’t normally occur


greg
2020-4-18 14:50:44

I mean there are many places on the continuum of “more vs. less ceremony” or “explicit vs. implicit”, and there are always trade-offs.


greg
2020-4-18 14:50:54

As usual, the right point is, “it depends”. :smile:


greg
2020-4-18 14:51:26

I think that goes for judicious use of non-hygienic macros, too.


laurent.orseau
2020-4-18 14:51:48

Also “docs” :wink: