-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add spawn! and try! macros #11892
Comments
I think another thing would that would make this even cooler would be to allow braces on expression macros. Then you could do this: spawn! {
// do some computation
} Whereas today you're forced to use parentheses. |
Yeah, we really need to allow braces here. I'm not sure why we can't. @paulstansifer, @jbclements |
I'd suggest holding off on |
I'm worried about adding a special-cased macro for something like this, as there are no doubt many other functions that are going to take a single procedure as a parameter. It isn't something you should have to do every time for nice syntax. |
@brson Is the idea that the invoker would be able to chose whether to use We briefly had macros always take |
@paulstansifer yes, that's what I was thinking |
Why is the |
@sfackler only in an item context; can't do it in an expression context (e.g. |
@thestinger maybe we can create a macro that creates macros like |
@paulstansifer there are no parse ambiguities for curlies? sounds good to me... |
No ambiguities. The |
@brson the point of try! is to make it more common. Today, one of the major reasons not to use The // uses fictitious IO APIs as an example
fn readlines(filename: &str) -> Result<~[~str], IoError> {
let file = try!(files::open(filename));
let body = try!(file.read());
body.split('\n').collect()
} This makes it easy to linearize a bunch of calls to functions that return results without introducing extra levels of indentation or adding limitations to interspersed code. While |
@wycats That is not what I thought the |
Oh, but since
|
A |
That seems like it'd be a bit confusing. Wasn't the early return macro called |
@sfackler I'm not too hung up on the name, but I think it's a good thing to avoid multi-word underscored names for commonly used language features. In my ideal world, macros wouldn't require parens and the above code would look like: // uses fictitious IO APIs as an example
fn readlines(filename: &str) -> Result<~[~str], IoError> {
let file = try! files::open(filename);
let body = try! file.read();
body.split('\n').collect()
} |
This makes using control-flow-y macros like `spawn! { ... }` more fluent and natural. cc rust-lang#11892.
This makes using control-flow-y macros like `spawn! { ... }` more fluent and natural. cc rust-lang#11892.
What's left to be done here?
|
I think the goal was to make |
This can probably be closed at this point, since this would only save 2 characters over unboxed closures. |
Agreed. |
…_time, r=Manishearth rename `DocMarkdown` pass to `Documentation` Followup of rust-lang#11801 This was discussed in todays meeting: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Meeting.202023-11-28/near/404667082 Decided to go with `Documentation`, because this would also make it consistent with how `Attributes` is named in `attrs.rs` (and it also sounds good). changelog: none
Once #11868 is through, I think this (partially suggested by @brson) is a good idea.
The text was updated successfully, but these errors were encountered: