-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Something that is still missing in MeTTa is a built-in support for lambda abstraction. Also, given that JeTTa apparently is going to support it, I think it's time we have a discussion about it to craft it exactly the way want while we can.
Here is my initial proposal
I suggest the following syntax
(\ PATTERN_1 ... PATTERN_N BODY)
where PATTERN_i is a pattern corresponding to the ith argument. Like in a regular MeTTa function, all patterns must unify with their respective arguments in order to beta-reduce.
For instance, the following call that takes the head of an empty list
((\ (Cons $head $tail) $head) Nil)
would not reduce, but
((\ (Cons $head $tail) $head) (Cons a Nil))
would.
Next, below is an example of a call with an n-ary function
((\ $x $y $z (+ $x (+ $y $z))) 1 2 3)
which would return [6].
The reason I suggest this syntax to define nary functions instead of say
(\ ($x $y $z) BODY)
is because, first, it is more consistent with the named function definition. For instance we say
(= (ternary-plus $x $y $z) BODY)
not
(= (ternary-plus ($x $y $z) BODY)
Although we can if we want to, we can do both!
And second, it is more consistent with type definition as well, for instance
(\ $x $y $z BODY)
corresponds to a type of tuple of the same size
(-> Number Number Number Number)
4 in both cases.
I believe that once lambda abstraction is natively supported, generic algorithms like map-atom and fold-atom should be upgraded to support it.