Rfcs: Language feature: turboball as postfix operator

Created on 8 May 2019  路  2Comments  路  Source: rust-lang/rfcs

Have the ::() ( turboball / rotating-arm / sonic spin ) to be a general postfix operator.

This is a suggestion to the discussion at

and the proposed syntax is similar to turbofish but it doesn't collide with field access nor namespaces nor turbofish and it does not include new symbols.

for example, have..

a::(match) {
    // ..
}

..be equivalent to..

match a {
    // ..
}

and then possibly deal with macros as well:

have..

("{}", 1)::(println!);

..be equivalent to..

println!("{}", 1);

So applying this to the async and postfix situations,
If await is a "await prefix" (let x = await thing;), it's turboball would be let x = thing::(await);
If it's macro-like (let x = await!(thing);), it's turboball would be let x = (thing)::(await!).

note: as macro tokens would still require surroundings ((), [], {}), then macro cascading, if possible, would still require russian-dolling..

(
    (
        (res_res_res)::(try!)
    )::(try!)
)::(try!)

..unless you would always insert surrounding parenthesis - but this could interfere with other stuff, idk - or if you would treat unit-tuple (or "empty" as a sugar to the unit-tuple) as parenthesis surrounding insertion, something like..

res_res_res
    ::(())::(try!)
    ::(())::(try!)
    ::(())::(try!)

..and/or..

res_res_res
    ::()::(try!)
    ::()::(try!)
    ::()::(try!)

..then I guess cascading macros would work.


I don't know if every expression "modifier"/variant should be included (or if this makes sense).

For example..

object
    .a()
    .b()
    .c()
    ::(&)

..may be equivalent to..

&object
    .a()
    .b()
    .c()

or even, if..

result::()::(try!)

..were equivalent to..

try!(result)

..then the ExprTry (result?) wouldn't be necessary.

Except that as a ExprTry structure, it still holds the "expression information" (see <ExprTry>::expr field) and not only "token stream information" (as normal macros do - see <ExprMacro>::mac.tts field). So ::(try!) couldn't really replace ExprTry structure (and it's inner information).


About calling functions that require multiple parameters, the linked discussion suggests using clojures for that. If not by this, I'd personally prefer inserting the parameters into a tuple and then calling a loosened wrapper of the desired function - or use some mapping (like a loosening map) to destructure the input and forward to the normal desired function.

So the example foo(24, bar(baz(data), 42)) would be..

baz(data)
    .pipe(|bar_0| bar(bar_0, 42))
    .pipe(|foo_1|, foo(24, foo_1))

..and would not require turboball (like what was suggested by CAD97).

A-operator A-syntax T-lang

Most helpful comment

I've published a crate for anyone interested in exploring this syntax: https://crates.io/crates/sonic_spin

All 2 comments

I've published a crate for anyone interested in exploring this syntax: https://crates.io/crates/sonic_spin

Hmm, if we had postfix match then

.pipe(|bar_0| bar(bar_0, 42))

would be

.match { bar_0 => bar(bar_0, 42) }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

onelson picture onelson  路  3Comments

3442853561 picture 3442853561  路  3Comments

rudolfschmidt picture rudolfschmidt  路  3Comments

silversolver1 picture silversolver1  路  3Comments

mqudsi picture mqudsi  路  3Comments