6 ms·
It looks like Rust doesn't have your dad's Lisp macros and more like C-style macros on steroids. Disclaimer: I haven't read The Book.
by cheez 9y ago
It looks like Rust doesn't have your dad's Lisp macros and more like C-style macros on steroids. Disclaimer: I haven't read The Book.
- navaati 9y agoWell C macros work at the text-level, Rust macros run at the AST level (but not the type level, that is you cannot construct syntactically incorrect stuff but you can construct wrong-typed stuff). So I don't really know lisp macros but I guess it's still closer than to C.
- foldr 9y agoRust macros actually work more at the token level than at the AST level.
- navaati 9y agoOh I see, thx !
- RReverser 9y agoThey work on both - for example, if you specify $expr:expr, it will actually parse it as an expression node and won't allow to simply pass it into another macro as $pat:pat because of AST node type mismatch even if actual tokens are still compatible.
- foldr 9y agoThat's a good point. What I was trying to get at is that Rust macros don't let you manipulate ASTs in any straightforward way. So they are not best thought of as AST -> AST transforms.
- kibwen 9y agoRust macros are Scheme macros, there's no similarity to C.
- ChrisSD 9y agoI don't think "C-style macros on steroids" is at all a good description. Rust's macros and C's really aren't that similar. If you want a short introduction to what Rust's macros actually are then try this: https://danielkeep.github.io/practical-intro-to-macros.html#macro-parsing-and-expansion https://danielkeep.github.io/practical-intro-to-macros.html#...
- fleetfox 9y agoWould Lisp macros make sense in language that is not homoiconic?
- maxiepoo 9y agoYes: http://calculist.org/blog/2012/04/17/homoiconicity-isnt-the-point/ http://calculist.org/blog/2012/04/17/homoiconicity-isnt-the-...
- mcguire 9y agoFine. Would lisp macros make sense in a language that isn't fully parenthesized?
- wtetzner 9y agoYes: https://www.cs.utah.edu/~rafkind/papers/honu-2012.pdf https://www.cs.utah.edu/~rafkind/papers/honu-2012.pdf Honu is a language with Javascript-like syntax, but has support for syntax-case style macros.
- Avshalom 9y agoFactor https://factorcode.org/ https://factorcode.org/ by comparison to gp's article Facotr macros are easy because instead of knowing exactly where and what the arguments are in Factor the reader doesn't have to care.
- kazinator 9y agoMany Lisp dialects are not homoiconic, as defined in the Wikipedia page for "homoiconic". Homoiconic means that procedures are stored in representation in which they are written, or more or less. A Lisp that compiles everything entered at the REPL isn't homoiconic. The input looks like (lambda (...) ...), but the storage is some block of x86 machine code with an environment vector. POSIX shells are homoiconic. When you type set, you see your functions, in source code form (modulo reformatting). The thing you want for metaprogramming is a smart internal representation of program text (not same as the external one).
- shmolyneaux 9y agoThere is a common set packages [0][1][2] that provide macros that are more similar to lisp-style macros (when operating on structs). [2] in particular implements quasi-quoting in rust. [0]: https://doc.rust-lang.org/proc_macro/index.html https://doc.rust-lang.org/proc_macro/index.html [1]: https://github.com/dtolnay/syn https://github.com/dtolnay/syn [2]: https://github.com/dtolnay/quote https://github.com/dtolnay/quote
- wtetzner 9y agoThey're actually closer to syntax-rules in Scheme.