Settings

Theme

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

medium.com

4 points by andrew-lucker 8 years ago · 2 comments

Reader

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-luckerOP 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.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection