Hacker News new | ask | show | jobs
by devrandomguy 3224 days ago
Clojure's macros can be made hygienic using `gensym`. Is this not enough? Is it desirable to Schemers for it to be impossible to generate user-accessible symbols within a macro?

What if symbols in macros were hygienic by default, but we had a `pubsym` escape hatch, allowing us to specify the exact symbol name. Would that allay safety concerns, or does that make something else difficult/impossible?

2 comments

Gensym is not enough. There are two kinds of hygiene: avoiding capture by the macro of identifiers used in expressions supplied by the user, and avoiding capture by the user of identifiers supplied by the macro. See http://community.schemewiki.org/?hygiene-versus-gensym and, I guess, https://en.wikipedia.org/wiki/Hygienic_macro#The_hygiene_pro... . (There are surely better presentations of the idea out there, but I can't seem to find them right this minute.)
Hygiene is a nicety that indeed can be emulated by unhygienic macros.

First class continuations however are less easy, and just as big a part of scheme. Callcc is a cult, nearly, and for good reason. With it, almost all local control patterns can be easily implemented so you can have things like fibers, coroutines, etc basically for free. It gets harder when you want asynchrony and parallelism, Andy Wingo has a great blog about guile internals and delimited continuation implementation, CML stuff, etc. If you're interested in higher-level scheme implementation, that's a good starting point.

Clojure has advanced control flow mechanisms and more sophisticated parallelism features than most scheme implementations, but this relies a lot on the underlying host platform. Callcc is made possible at the fundamental level of how scheme works. Pmaps in clojure work because the jvm is incredible and js engines are getting there too. LLVM is not the magic bullet for excellent language design, sometimes.