7 ms·
The thing keeping me from Rust is the weaker metaprogramming relative to C++. Do you have plans to expand Rust to things like compile-time expressions, template
by stochastic_monk 8y ago
The thing keeping me from Rust is the weaker metaprogramming relative to C++. Do you have plans to expand Rust to things like compile-time expressions, template templates, and perfect forwarding?
- steveklabnik 8y agoWe do! We've been pretty quietly developing it, but right now, the Rust compiler contains a full interpreter as well, specifically to do compile-time evaluation. But, we also do not want to have unlimited compile-time facilities, as that has serious soundness problems. "const fn" is the name of the user-facing feature, and MIRI is the underlying interpreter, if you want to do some searching. That said, that work tends to fall under "compile time expressions"; "template templates" are more likely to be served by some sort of eventual HKT, or maybe even by ATC. I always forget what perfect forwarding is so I probably shouldn't comment on it. I am willing to bet that this stuff is a major part of next year's roadmap, but we'll see!
- Sharlin 8y agoFor the uninitiated, HKT means higher kinded types, which is the type theoretic term for what C++ calls template template parameters. That is, the possibility to pass around type-level functions. I don't know what ATC refers to.
- steveklabnik 8y agoYes, thank you! ATC is "associated type constructors". I believe Haskell calls them "type families"? It's sort of a similar idea; a form of higher-kindness. We are likely to get ATC in the medium term, but full HKT is farther out.
- Sharlin 8y agoRight, thanks! It sounded familiar but google revealed nothing. Should have tried "atc rust".
- deleted 8y ago[deleted]
- senorsmile 8y agoThere's a ticket about this. The linked comment in particular gives a good background on what HKT's are, and how they could look in Rust: https://github.com/rust-lang/rfcs/issues/324#issuecomment-248779799 https://github.com/rust-lang/rfcs/issues/324#issuecomment-24...
- mamcx 8y agoI wish the macro system was more ergonomic, like this: fn %identifier(value:%type) -> %type { BytesMut::from(value) } ie, to look like html templates like handlebars or similar.
- steveklabnik 8y agoProcedural macros can have this, in a sense; see this crate: https://crates.io/crates/quote https://crates.io/crates/quote
- baby 8y agoI have a question about that actually, macros in C/C++ are disgusting, why isn't Rust trying to improve it? It's better obviously but it is still not a nice thing to parse.
- steveklabnik 8y agoRust macros are almost nothing like C or C++ macros; they operate on an AST, not on the literal text.
- baby 8y agoI'm talking of the syntax. Why can't I write a macro in more rust-like form for example instead of a very different language
- steveklabnik 8y agoWell, patterns are a very different language than rust; rust has no way to express “one or more of this thing” for example. I wasn’t involved when the syntax was chosen, and that was well before our RFC process, so I don’t have any real, deep explanation for you, sorry!
- mamcx 8y agoIn fact thinking about the same, and because I'm building a toy language, a macro system could look like: https://elixir-lang.org/getting-started/meta/macros.html https://elixir-lang.org/getting-started/meta/macros.html
- CodesInChaos 8y agoConst fn is being worked on (available in unstable rust). C++ style templates (if that's what you mean by template templates) are not something that is planned for Rust, but some limited forms of specialization are being considered (a simple version is available in unstable). For powerful meta programming Rust aims for procedural macros, not for templates, but I'm not too familiar with the details.
- steveklabnik 8y ago> For powerful meta programming Rust aims for procedural macros, not for templates, but I'm not too familiar with the details. Yes, this is a good point. We want Rust to have powerful compile-time metaprogramming, but we also want to do it in a Rust-y way, not blindly copy C++ or any other language.
- baby 8y agoThanks, C++ metaprogramming is awful. Please think of the people who have to read other people's code :)
- stochastic_monk 8y agoThat’s totally fine. Most importantly, I want to work well with functors, generic functions, and compile-time evaluation (for things like manual loop unrolling and so on). I value expressivity, and I appreciate your efforts! I don’t think it will be long before I try it out.