zcaudate
zcaudate

Reputation: 14258

Implementing scheme style macros in clojure

I often read debates about why hygenic macros are better and that clojure's macro system is based upon Common Lisp and is not hygenic.

My question is: can a scheme style macro system be implemented in clojure and what are some examples of scheme style macros implanted in other lisps.

Upvotes: 6

Views: 524

Answers (2)

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91534

I'm not sure it's accurate to say that Clojure's macro system is not hygienic. One similar discussion I have seen refers to common lisp's system for reader macros (which Clojure does not have) as being not hygienic because they lack a mechanism to keep reader macros in different modules from replacing each other. It was an explicit and intentional design decision to build the language such that Scheme-style macros where not included.

Upvotes: 2

Greg Hendershott
Greg Hendershott

Reputation: 16250

By "Scheme-style macro system", I'm not sure if you mean syntax-rules (the simple pattern style system) or syntax-case (the more flexible system which, along with datum->syntax, actually does let you bend or flat-out break hygiene).

Also, Racket has syntax-parse, which a bit simpler to use than syntax-case and (among other things) makes it pleasant to write macros which give intelligible error messages.

Regardless of which you mean, there is a Clojure project that purports to implement aspects of all three. However I haven't tried it and I can't vouch for how successfully it does so.

Upvotes: 5

Related Questions