Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up`box` syntax #405
Comments
This comment has been minimized.
This comment has been minimized.
thestinger
commented
Oct 23, 2014
|
It's important for |
This comment has been minimized.
This comment has been minimized.
|
I like |
This comment has been minimized.
This comment has been minimized.
|
(The other (IMO more important) reason why PLACE should appear somewhere to the left of EXPR is that it properly reflects the evaluation order, which is indeed the whole point of having this syntax in the first place. edit: okay, maybe not "whole point", but its significant...) |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 25, 2014
|
It's never been clearly documented anywhere what the idea behind and plans for this syntax are, and that will inform this discussion significantly. For instance, I was surprised to see @thestinger say that this syntax should support collection inserts, I thought it was mostly for allocations i.e. |
This comment has been minimized.
This comment has been minimized.
thestinger
commented
Oct 25, 2014
|
It's meant to cover the same use cases as placement new and perfect forwarding in C++. Those allow in-place construction of elements in smart pointers, collections and more. |
This comment has been minimized.
This comment has been minimized.
dobkeratops
commented
Oct 25, 2014
|
How about, expresses its refinement of the 'box', like box(?) does, but more syntactically compact and unambiguous due to location of box vs . I think that would be very clear to read, but I realise it has no precedent in the syntax, it might be hard to guess. Then again its not like box(Gc) was a function call either. |
This comment has been minimized.
This comment has been minimized.
|
@dobkeratops how does that work with in-place construction in containers, or even just a custom allocator with |
This comment has been minimized.
This comment has been minimized.
dobkeratops
commented
Oct 25, 2014
|
box.vec.emplace_back() foo() ... ok thats a bit messy, but it does still get rid of the ambiguity I haven't seen the proposes for emplace back... would it make sense for it to read a bit like 'method of the container' - and reverse it e.g. vec.emplace_back().box foo() not sure which makes more sense or is least confusing. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
with #809 merged, I'm going to give this a close. If any of the concerns in this thread weren't addressed, let's open new issues specific to that (though I think they were) |
P1start commentedOct 23, 2014
The current
boxsyntax (box(PLACE) EXPR) has a few flaws in my opinion:This syntax never went through a proper RFC, so it didn’t get much feedback. Here are some ideas I’ve come up with or have maybe seen about the place; I don’t really like any of them much, but they mostly fix my issues with the current syntax:
box(in PLACE) EXPR: resolves parsing issues, but looks a bit weird;box EXPR in PLACE: resolves parsing issues and looks less like a function call, but moves the place to the end, which is not usually desirable as the expression is usually longer;box::(PLACE) EXPR: resolves parsing issues and looks very weird, but less like a function call. Steals syntax from disambiguating generic method calls;box(PLACE) EXPR(the current syntax), but after parsing the)after the place, check that the next token can start an expression (the strategy adopted by rust-lang/rust#16863). Still has a bit of ambiguity inif/while/forexpressions (e.g.,if foo == box (bar) { ... }), but otherwise resolves most parsing issues. Has the advantage of simplicity.If the current syntax stays, we should at least omit a helpful message whenever the expression is missing from a
boxexpression. I plan on implementing this shortly.