Thanks for this explanation about ~! Can you add a paragraph in the
tutorial or manual?
Le 30 nov. 2013 08:10, "Kevin Ballard" <ke...@sb.org> a écrit :

> As I said in the IRC channel, the reason why users often don't realize
> that `~T` is allocation, is not a failure of syntax, but a failure of
> documentation. The only reason why a user would know that `new Foo`
> allocates is because they've been exposed to that syntax from another
> language, one that actually documents the fact that it allocates. Users who
> haven't been exposed to `new Foo` from other languages will have no reason
> to understand that this allocates without being told that it allocates.
>
> As such, there is no reason why we cannot simply fix the documentation to
> explain that `~` is the allocation operator, and that when it's used in an
> expression it means it allocates a value.
>
> It was then explained to me that the "real" reason we needed `new` wasn't
> because of the issues with users understanding allocation, but because of a
> need for placement new. That is why I suggested some alternative syntaxes.
>
> Also, FWIW, `~(n + m)` makes sense, as a way of producing an allocated
> value from the result of `n + m`, but `new (n + m)` is pretty nonsensical.
>
> -Kevin
>
> On Nov 29, 2013, at 10:48 PM, Patrick Walton <pwal...@mozilla.com> wrote:
>
> None of these look like allocation.
>
> Patrick
>
> Kevin Ballard <ke...@sb.org> wrote:
>>
>> I am very saddened by the fact that we're apparently reserving `new` as a 
>> keyword, and even more by the fact that the proposed placement new syntax is 
>> `new(foo) bar`. This looks exactly like C++, and it goes against the strong 
>> precedence we already have of using new() as a static function for types. 
>> Path::init("foo") looks extremely wrong to me.
>>
>> Surely there's another syntax we can use for placement new that doesn't 
>> involve reserving `new` as a keyword? Here's a few random ideas (where "val" 
>> is the value expression and "place" is the place expression):
>>
>> ~in(place) val
>> in(place) ~val
>> ~val in place  (assuming this isn't somehow ambiguous)
>> ~~val in place (the existing ~~val would have to be written ~(~val))
>> ~~(place) val  (the existing ~~val would have to be written ~(~val))
>> ~<place> val
>> ~=place val
>> ~>place val    (this looks like an arrow pointing to the place)
>> ~>(place) val
>>
>> Personally I think `~in(place) val` is perfectly fine. It's not the 
>> prettiest of syntaxes, but placement new should be very rare, and this 
>> allows us to avoid reserving `new` and continue to use ~ as the allocation 
>> operator.
>>
>> -Kevin
>>
>>
>> ------------------------------
>>
>> Rust-dev mailing list
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to