initialization syntax

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

initialization syntax

范长春
Hi Rust designers,


I'm curious why rust uses colon ":" instead of assignment "=" when initialize an object. What is the rationale behind this?


Reply | Threaded
Open this post in threaded view
|

initialization syntax

Patrick Walton
Because of JavaScript, basically.

Patrick

On July 11, 2014 9:21:20 PM PDT, "???" <changchun.fan at qq.com> wrote:

>Hi Rust designers,
>
>
>I'm curious why rust uses colon ":" instead of assignment "=" when
>initialize an object. What is the rationale behind this?
>
>
>From what I see, `Point { x = 2, y = 3 }` looks much better than `Point
>{ x : 2, y : 3}`.
>
>
>Since most of the syntax rules are consistent in rust, why we use `:`
>to represent different two meanings?
>
>
>I'm new to Rust now. Just can't get the concept behind the design.
>
>
>Thank you in advance
>Changchun
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Rust-dev mailing list
>Rust-dev at mozilla.org
>https://mail.mozilla.org/listinfo/rust-dev

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140711/1d5e14b0/attachment.html>

Reply | Threaded
Open this post in threaded view
|

initialization syntax

Nick Cameron
In reply to this post by 范长春
The short answer is so that struct initialisation, struct types, and struct
de-structuring all have the same syntax.

For more detail, see the discussion in this (rejected and closed) RFC for
changing from using `:` to `=`.

Cheers, Nick


On Sat, Jul 12, 2014 at 4:21 PM, ??? <changchun.fan at qq.com> wrote:

> Hi Rust designers,
>
> I'm curious why rust uses colon ":" instead of assignment "=" when
> initialize an object. What is the rationale behind this?
>
> From what I see, `Point { x = 2, y = 3 }` looks much better than `Point {
> x : 2, y : 3}`.
>
> Since most of the syntax rules are consistent in rust, why we use `:` to
> represent different two meanings?
>
> I'm new to Rust now. Just can't get the concept behind the design.
>
> Thank you in advance
> Changchun
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140712/ac105ac3/attachment.html>

Reply | Threaded
Open this post in threaded view
|

回复: initialization syntax

范长春
Thank you for your explanation. But I didn't find the RFC you mentioned.

I have a question that what if we need both struct initialization and struct type declaration in one expression in future?

For example, C#'s `anonymous struct` feature is useful in Linq expression. Do we make sure that `anonymous struct` will never be added to Rust language?

Thanks,
Changchun
------------------ ???? ------------------
???: "Nick Cameron"<lists at ncameron.org>
????: 2014?7?12?(???) ??12:34
???: "???"<changchun.fan at qq.com>;
??: "rust-dev"<rust-dev at mozilla.org>;
??: Re: [rust-dev] initialization syntax


The short answer is so that struct initialisation, struct types, and struct de-structuring all have the same syntax.


For more detail, see the discussion in this (rejected and closed) RFC for changing from using `:` to `=`.
 

Cheers, Nick



On Sat, Jul 12, 2014 at 4:21 PM, ??? <changchun.fan at qq.com> wrote:
 Hi Rust designers,


I'm curious why rust uses colon ":" instead of assignment "=" when initialize an object. What is the rationale behind this?
 

Reply | Threaded
Open this post in threaded view
|

initialization syntax

Nick Cameron
Whoops! I meant to paste in the URL, but forgot -
https://github.com/rust-lang/rfcs/pull/65 Sorry about that.

We used to have anonymous structs and they were removed (before my time, so
I can't tell you the reasons, sorry), so it is very unlikely we'll get them
back. If we did want to, then they could be added backwards compatibly, so
they could be considered post-1.0.

Cheers, Nick


On Sun, Jul 13, 2014 at 5:13 AM, ??? <changchun.fan at qq.com> wrote:

> Thank you for your explanation. But I didn't find the RFC you mentioned.
>
>
> I have a question that what if we need both struct initialization and struct type declaration in one expression in future?
>
>
> For example, C#'s `anonymous struct` feature is useful in Linq expression. Do we make sure that `anonymous struct` will never be added to Rust language?
>
> Thanks,
> Changchun
> ------------------ ???? ------------------
> *???:* "Nick Cameron"<lists at ncameron.org>
> *????:* 2014?7?12?(???) ??12:34
> *???:* "???"<changchun.fan at qq.com>;
> *??:* "rust-dev"<rust-dev at mozilla.org>;
> *??:* Re: [rust-dev] initialization syntax
> The short answer is so that struct initialisation, struct types, and
> struct de-structuring all have the same syntax.
>
> For more detail, see the discussion in this (rejected and closed) RFC for
> changing from using `:` to `=`.
>
> Cheers, Nick
>
>
> On Sat, Jul 12, 2014 at 4:21 PM, ??? <changchun.fan at qq.com> wrote:
>
>> Hi Rust designers,
>>
>> I'm curious why rust uses colon ":" instead of assignment "=" when
>> initialize an object. What is the rationale behind this?
>>
>> From what I see, `Point { x = 2, y = 3 }` looks much better than `Point {
>> x : 2, y : 3}`.
>>
>> Since most of the syntax rules are consistent in rust, why we use `:` to
>> represent different two meanings?
>>
>> I'm new to Rust now. Just can't get the concept behind the design.
>>
>> Thank you in advance
>> Changchun
>>
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev at mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140713/b27b5037/attachment.html>