-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
It can be possible that we want to match a particular value in runtime, but currently that's not possible: any identifier inside a pattern is interpreted like an assignment to that name. Elixir solves this with a prefix operator, specifically the caret (^). I think that we could use a similar solution, even with the same operator (for familiarity).
For example, let's say we have a case expression inside a function:
let f(list, value) :=
let a := case list do
[value|tail] => tail
_ => []In this case, we are shadowing value and giving it the value of the first element in list. With a caret operator behaving the same as in Elixir, we could do:
let f(list, value) :=
let a := case list do
[^value|tail] => tail
_ => []and the function would do an entirely different thing: it would return the tail of list only if its first element is equal to value.
Reactions are currently unavailable