Hello,

I'm new here, just someone trying to like Rust but not fully convinced yet.
That makes me a nobody, but I figured I'd throw in my two cents. The recent
'do' discussion reminds me of some of my own favorite syntax ideas on this
matter. While Ruby's |args| syntax is somewhat recognizable by now, I think
the following is nice:

whatever(do(args) {
    ...
});

Or that could be used like so as a trailing argument:

whatever do(args) {
    ...
}

Or some variation on that theme. This would give fn@ blocks and do blocks
(stack closures) both with keywords. This makes syntax differences lest
jarring, as in this example from the tutorial. Original:

fn call_twice(f: fn()) { f(); f(); }
call_twice({|| "I am a stack closure"; });
call_twice(fn@() { "I am a boxed closure"; });
fn bare_function() { "I am a plain function"; }
call_twice(bare_function);

Proposed syntax:

fn call_twice(f: fn()) { f(); f(); }
call_twice(do() { "I am a stack closure"; });
call_twice(fn@() { "I am a boxed closure"; });
fn bare_function() { "I am a plain function"; }
call_twice(bare_function);

In addition to eliding the {} for single expressions, perhaps empty parens
could also be elided, as in 'call_twice do {"I am a stack closure";}' or
something like that. I think 'do' is prettier, carries an automatic name,
and would be more consistent than the current (do plus ||) proposals.

Anyway, I agree with ret/break/continue treating things as blocks only for
the trailing {} case.

Well, as I said, I'm just a many-year migrant trying to figure out what I'd
really like to use while failing to have the commitment/time to make
something of my own. Just wanted to give my two cents (or maybe just half a
cent) on this syntax.

- Tom

On Sat, Jun 9, 2012 at 5:43 PM, Patrick Walton <[email protected]> wrote:

> On 06/09/2012 02:24 PM, Gareth Smith wrote:
>
>> As I understand it, given point 2 of the proposal, the above code would
>> not be valid. Instead it would look like:
>>
>> spawn(|| {
>> ...
>> });
>>
>> Is that correct? If so, would the semantics of the directly above be
>> identical to:
>>
>> do spawn {
>> ...
>> }
>>
>> ?
>>
>
> Yes, except that continue/break/ret would be valid in the latter but not
> the former.
>
> Patrick
>
> ______________________________**_________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to