I actually work on a JS project that needed to heavily rely on macros to reduce build file size (the project is from before ES6 and rollup.js). I ended up going to MetaScript [1] as all of its syntax was based on comments. So all the other tooling and code highlighting worked without issue.
Typescript doesn't officially support macros yet, but if you want to live dangerously (which you would if you were choosing to use Sweet.js!) you can check out https://github.com/cevek/ttypescript#transformers :)
> Currently, Sweet should be considered experimental and under heavy development (re-development more like). As such, the API will be undergoing a bit of churn until probably the end of the year. So, probably best not to try Sweet in production systems just yet. If you're interested in helping out though we'd love to have you!
Project last updated 2 years ago. I think this is dead.
Racket likely has the most sophisticated (mostly) hygienic macro system out there. In particular, syntax parameters are a really neat feature which lets you implement things normally requiring breaking hygiene in a hygienic way. For example, implementing early return using return as a keyword can be done using a syntax parameter which allows for nesting, renaming the “return” if you want, and composing it with other macros which utilize their own “return” keyword.
Racket truly has some great stuff wrt. macros -- I'm not sure if it was invented as a research vehicle for macros specifically[0], but they've even gone as far as implementing fairly advanced type systems as macros[1].
Besides the one I've linked, they have lots of interesting papers around the macro system: the handling of 'stages', the modularity, etc. Basically just google "Racket [something]" and go from there :)
[0] Probably more just a general 'extensible languages' type thing?
I only glanced over the paper but its novelty seems to lie in the turnstile language itself, i.e. the design of a metalanguage to define EDSLs that have a typesystem.
Yes, it is built using macros and I assume cleverly uses whatever macro system features Racket provides so there is possibly something novel there as well.
However, the fact that it can be done or has been done on its own is not quite so surprising to me. If you have the ability to inspect syntax you can obviously do something like that.
It is a little bit of a shame that it doesn't seem to be under active development anymore. For personal projects, it would be fun to be able to write up little DSLs
It seemed to undergo a major rewrite and then died.
I could also never really figure it out post-rewrite. Pre-rewrite, I had made some cool macros just out of intuition after reading some of its examples. Now, I can't get many of its own examples to compile in its live editor.
Too bad. It's about 1000x simpler than, say, implementing low-level Babel transformations.
I feel the pain. Things got a little bit easier with Babel Plugin Macros and Typescript (which forces you to build macros that adhere to a reasonable type system)
These "macros" take a different approach than Sweet.js: they're not syntax extensions, but rather code transformers that you import and use explicitly.
After falling in love with Clojure and then Clojure being rejected by my company, I so wanted Sweet.js to become a thing. Macros allow for some incredible magic and amazing productivity, in my experience. Unfortunately, Sweet.js looks abandoned last I checked. And I'd be surprised if I could sell my company on it.
I wonder, ES6 template strings allow any kind of string inside them which can be constructed based on existing values in the surrounding function. So I can give such a string as argument to a function which returns some non-string JavaScript value, perhaps a function.
Are there any active projects that do anything similar?
The two things I'd quite like to transform are
In a es2015 Class function if base identifier foo is a class field (in this or ancestor class) it becomes this.foo . Only for fields defined in the Class definition.
Was a great project. I experimented with it about 5 years ago and really liked what I saw. But at the end of the day, it's not so fun having syntax that none of your tooling understands.
Hygienic macros are aware of what they are using. For example, if your macro uses leftpad, calling code does not need to import or be aware of leftpad. Also, consider the issues around writing a swap macro using eval, how do you introduce a temporary which is guaranteed to not conflict with the caller’s code? Hygiene solves this by saying the macro’s temp variable is not the same as the calling code’s temp variable.
2014: https://news.ycombinator.com/item?id=7978897
https://news.ycombinator.com/item?id=7219267
2012: https://news.ycombinator.com/item?id=4650929
https://news.ycombinator.com/item?id=4560691