top | item 15874387

Things you can’t do in Rust: destructure function arguments in declaration

4 points| andrew-lucker | 8 years ago |medium.com

2 comments

order

arh68|8 years ago

> shorthand for a function with only a pattern as its body.

Only an expression as its body seems more like it.

Just to be clear, would you require the last function clause to be a catch-all/wildcard pattern? Or could you just define a function on 0 & 1? Separate question: would you want to be able to add a new clause for your function f below main? It's okay to want either outcome, I'm just curious. Third question: would you want/accept a delimiter between a function's clauses like ; or | ?

I like the idea. Especially if you can still refer to pattern-matched parameters by name, too.

andrew-lucker|8 years ago

Not married to the syntax, just wanted to highlight the absence of this syntax form. The syntax used was mainly meant to mirror the existing Rust pattern syntax.

As for partial matching, other languages give warnings or errors if a pattern doesn't cover all cases.