A Practical Intro to Macros in Rust
danielkeep.github.io
A Practical Intro to Macros in Rust
1–10 of 26 posts
Re: A Practical Intro to Macros in Rust
#2Re: A Practical Intro to Macros in Rust
#3The impetus for this is that the macro system was unanimously considered the least mature feature of pre-1.0 Rust, but there was little will to delay Rust 1.0 even further solely for the sake of macros. Instead, some expedient band-aids were slapped over it during the run-up to 1.0, with the intent to eventually fix the whole thing properly when time allowed.
To wit, the main problems with macros 1.0 were that macro "importing" is an ugly hack that stands out like a sore thumb from how modules work in the rest of the language; in addition, despite supposedly being hygenic, there are some edge cases where hygiene does not hold. The new system will make the language overall more consistent and reliable (and might bring some minor syntactic improvements), with the obvious downside that making the macro system nicer to use means that people might actually start using it. :P
Re: A Practical Intro to Macros in Rust
#4Re: A Practical Intro to Macros in Rust
#5Re: A Practical Intro to Macros in Rust
#6The intro to macros starts with a recursive macro. Not a good approach for an intro. Recursion in macros is usually more of a toy than a useful tool, anyway.
This resource is a "learning by example" resource, and it teaches the macro bit by bit starting from a simplified version and building up to the recursive and complex part, teaching concepts along the way. That's a great way of structuring it.
Re: A Practical Intro to Macros in Rust
#7The intro to macros starts with a recursive macro. Not a good approach for an intro. Recursion in macros is usually more of a toy than a useful tool, anyway.
No, it starts with a non recursive macro that does less stuff, and builds up to the recursive one. This resource is a "learning by example" resource, and it teaches the macro bit by bit starting from a simplified version and building up to the recursive and complex part, teaching concepts along the way. That's a great way of structuring it.
Re: A Practical Intro to Macros in Rust
#8Re: A Practical Intro to Macros in Rust
#9Re: A Practical Intro to Macros in Rust
#10R7RS Scheme has `syntax-rules` which is very similar in structure to this macro system. It's quite elegant as it is, in my opinion, but I'm also wondering how good the debugging facilities for it are. Are they good?