// matches don't have to consume all of the parameters
// (although they can't define more clauses than the `match` arguments
match (x, y, z) {
(1) -> 2
(2) -> 3
(_) -> {
y = x + 1
f(y, x - 1)
}
}
A function could have a match expression body:
f = (x, a, p) -> { // <- function args
match (x, a, p) { // <- match inputs
(1) -> 2
(2) -> 3
(x) -> {
y = x + 1
f(y, x - 1)
}
}
}
There's a lot of redundancy and it's common for functions to match on all of their arguments, so we could define a shorthand. Some sketches:
f = (x, a, p) -> {
(1) -> 2
(2) -> 3
(x) -> {
y = x + 1
f(y, x - 1)
}
}
// shorter, more like current syntax
f = {
(1) -> 2
(2) -> 3
(x) -> {
y = x + 1
f(y, x - 1)
}
}```
// this is no good because match is an expression. This syntax would apply
// matching against local x, a, p rather than defining a new matching function.
f = match (x, a, p) { // <-- inputs and args!
1 -> 2
2 -> 3
x -> {
y = x + 1
f(y, x - 1)
}
}
Issue to capture ideas about a new
match
pattern matching expression, and a shorthand for defining a function that matches over all of its arguments.Right now functions can have several clauses, with pattern matching arguments:
Sketch for
match
expression:A function could have a
match
expression body:There's a lot of redundancy and it's common for functions to match on all of their arguments, so we could define a shorthand. Some sketches:
// this is no good because
match
is an expression. This syntax would apply // matching against localx, a, p
rather than defining a new matching function. f = match (x, a, p) { // <-- inputs and args! 1 -> 2 2 -> 3 x -> { y = x + 1 f(y, x - 1) } }