A Quick Intro to Rust Macros
danielkeep.github.io
danielkeep.github.io
That said, we're looking at interim ways of providing some sort of relief for people who want to metaprogram in Rust 1.0. There aren't any concrete plans yet, but we love the idea of user-defined macros and we're not going to leave people out in the cold if we can help it.
(And perhaps you're wondering why we don't delay Rust 1.0 until macros are ready? Because the rest of the language works (or very soon will work) just swimmingly, and it doesn't make sense to deny stability from people who can live without macros (whose definition mechanisms can be introduced without breaking backwards compatibility). Rust 1.0 will be only the beginning of a gradual transition towards ecosystem stability, not a sudden leap.)
I've been reading the official guides. Those helped clear up some difficult points for me: lifetimes and interfacing with lower level code.
http://doc.rust-lang.org/#guides
Also in what seems like a very short time, Rust community addressed the entries in Shootout Computer Benchmark game. Those are toy scores and one should not take them seriously. But unfortunately people do. So they made those fast.
http://benchmarksgame.alioth.debian.org/u64q/code-used-time-...
People keep saying that about The Shootout, but I don't think so. They reflect the combination of two qualities: the main implementation of the language, and the community around the language. It's way too cynical to say that the results cannot be taken seriously -- they just have to be taken carefully.
For instance, we can see that the Rust community was able to make their runs quite snappy quite easily, even though the implementation isn't even ready yet. That's impressive!
But what I was getting at is that those scores are non-toy like and important for PR purposes. And as you said, they represent how active or caring the community is (and how sensitive it is to its _perceived_ performance).
So kudos to Rust community!
http://forum.dlang.org/thread/lv7h1r$mg3$2@digitalmars.com?p...
The problem is that in quest for optimization the code for many languages becomes very much non idiomatic. Therefore the result does not accurately reflect real life performance, where writing idiomatic code outweighs the benefit of iterating on something to the nth degree in search of micro optimizations.
What you believe they reflect is not a claim made on the website.
I very much appologize and humble myself before the almighty benchmark gods. Please forgive me.
I'd rather the language designers assume that future tooling for IDEs and editors will syntax highlight macros.
But a macro invocation is special. The syntax within a macro does not follow Rust rules, so if macros would not be marked properly it would be incredibly confusing for a user. Let alone that macro imports are different by the very nature of their behavior.
But that doesn't mean that what's in the macro should be highlighted like Rust:
sql!("SELECT * FROM users WHERE name = $1");
is a macro provided by https://github.com/sfackler/rust-postgres-macros , and should be highlighted like SQL, not like a Rust string. sql!("SELECT * FORM users WHERE name = $1");
throws an error, because it's malformed.There is just a terrible mismatch between the use-case macros were originally intended for (embedding different languages) and how they are mainly used now (emulating varargs).
The current arguments from Rust people are mainly defensive in that area, but maybe they will revisit this as the community matures.
> There is just a terrible mismatch between the use-case
> macros were originally intended for (embedding
> different languages) and how they are mainly used now
> (emulating varargs).
This is incorrect. I can't think of any macros that are used to paper over the lack varargs (`println!` certainly doesn't count, because even if Rust had varargs you'd still need a macro here to do typesafe compile-time string parsing).In any case, varargs can already be trivially emulated using vectors (which afaict is essentially what Go does, but Go has sugar for it). Macros would be overkill for this use case.
> This is incorrect.
Eh ... did you have a look at the "standard" library? > `println!` certainly doesn't count, because even if Rust
> had varargs you'd still need a macro here to do typesafe
> compile-time string parsing
Yeah, but you could do it without exposing all the horrible mess to users.The usual "OMG!!! Look at that random `!`. Stand back, I'm using a macro here and would like to warn you that semantics will be totally different!!!"-dance is just embarrassing, especially given the fact that you can design printf-like functionality without needing varargs in the first place.
With or without macros, if your API requires warning signs it just sucks, and you should fix it instead of using "hey, but I warned people!" as an excuse.
> varargs can already be trivially emulated using vectors
Oh right! So how do we create a vector? vec![1, 2, 3, 4]
Oh well ...It's a warning that there's "magic" going on. It makes it clear that there's a lot of quirky compile-time type checking trickery behind printf, it tells that regex is going to be precompiled, etc.
Felt nearly the same way with "recur" in "clojure", instead of calling the function name recursively and pray the compiler would do the proper tail call optimization (elimination), but recur forces you to always get it right.