4 ms·
> I can't help thinking that this is just the wrong way to do this. I think this is a typical example for the huge verbosity of Rust. Yes, you get safe bare me
by progman 11y ago
> I can't help thinking that this is just the wrong way to do this.
I think this is a typical example for the huge verbosity of Rust. Yes, you get safe bare metal access but for the price of a lot of coding effort for _every_ application.
For comparison watch how easily syntax extensions are done in Nim. For instance,
template times(x: expr, y: stmt): stmt =
for i in 1..x:
y
10.times:
echo "Hello World"
http://hookrace.net/blog/what-is-special-about-nim/ http://hookrace.net/blog/what-is-special-about-nim/
- kibwen 11y agoUsing this as an example of Rust's verbosity is uninformed. The reason that syntax extensions are undocumented is because they are highly unstable and not intended for end-user consumption (users of Rust 1.0 will not be able to create syntax extensions). They operate by reaching deep into the guts of the compiler and directly playing with APIs that have been designed for consumption by compiler authors. That they are exposed at all in the unstable branch of Rust is because Rust is a language that prefers to shove as much logic out of the compiler and into the stdlib as it can, and syntax extensions are one mechanism by which this is currently achieved. Furthermore, your example is misguided. Syntax extensions are not for trivial rewriting, that's the purpose of macros. Syntax extensions are for doing things like expanding a regex into a finite state machine at compile-time, or providing custom extensions to Rust's type system. In terms of tools, they are a 40-foot industrial lathe which can do anything, but is overkill for the vast majority of tasks.
- progman 11y ago> Syntax extensions are not for trivial rewriting, that's the purpose of macros. Syntax extensions are for doing things like expanding a regex into a finite state machine at compile-time. Nim provides templates and macros for that. Templates are for rewriting while macros can create arbitrary AST nodes. http://blog.ldlework.com/2015/05/01/a-cursory-look-at-meta-programming-in-nim/ http://blog.ldlework.com/2015/05/01/a-cursory-look-at-meta-p...