Lisp/Julia style macros/codegen

Curious if Mojo will feature this. Many benefits, but among other things it would enable language users to add syntactic and code generation features without having to wait for the core language to be updated.
10 Replies
ModularBot
ModularBot•8mo ago
Congrats @Alex Gunnarson, you just advanced to level 1!
Nick!
Nick!•8mo ago
Mojo already supports metaprogramming (code generation) via its parameter system. I wouldn't expect Mojo to support macros until/unless the community identifies a sufficient number of compelling use-cases for them. It's also worth noting that in languages that have macros, most people advise that "you shouldn't use macros unless you REALLY need them". So macros are are a pretty sus feature.
sora
sora•8mo ago
I wish we could have some very restricted form of macro system that barely allows us to implement @value etc. in Mojo.
Alex Gunnarson
Alex Gunnarson•8mo ago
I know what you mean @Nick!. Though I wouldn't necessarily call it a "sus feature". Of the 1M+ LOC of Clojure I've written by this point (a Lisp dialect), macros have admittedly made up probably only 0.25%-0.5%. But not having those macros would have made life infinitely harder. Not just syntactic sugar and readability via abstraction, but necessary perf improvements as well (helping the compiler out). So going all in on a language that doesn't have fully generic macros is a bit of a non-starter to me. Time to build a Lisp transpiler for Mojo 😄 Having a macro system anticipates the addition of language features and puts control in the hands of language users. It prevents the core language from getting new syntax every year contingent on the gatekeeping whims of language maintainers. Even if users aren't clamoring for concrete use cases right now, I consider a macro system a must for any modern language. Otherwise we run straight into https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule.
Nick!
Nick!•8mo ago
I strongly disagree 🙂 Macros are very controversial, and their inclusion in any language should be very carefully considered We would first need to identify a large number of concrete problems that cannot be solved using any of Mojo’s current or planned language features. Then we could consider additional features (such as macros) that might be able to address those unsolved problems.
Alex Gunnarson
Alex Gunnarson•8mo ago
Sounds like a difficult-to-bridge difference in ideology. Have you used a macro-enabled language, especially a Lisp dialect? What was your experience there?
Heyitsmeguys
Heyitsmeguys•8mo ago
Just FYI, there exists a (currently inactive) PEP to add macros to Python (https://peps.python.org/pep-0638/). Also see the discussion about it here: https://discuss.python.org/t/pep-638-syntactic-macros/5352. So it's not like there isn't a demand for these features.
DanteOz
DanteOz•7mo ago
GitHub
[Feature Request] Syntactic Macros and First-Class Metaprogramming ...
Review Mojo's priorities I have read the roadmap and priorities and I believe this request falls within the priorities. What is your request? First-class metaprogramming with syntactic macros (...
Alex Gunnarson
Alex Gunnarson•7mo ago
Thanks for linking that!
Want results from more Discord servers?
Add your server