Postfix lambdas

Here is a paper explaining the addition of lambdas to Forth.

In the non-academic space, my language Enchilada has postfix lambdas via the eager macro operator.

Interestingly, Enchilada can avoid the name capturing problems that plague Lisp macros (although some Lisp hackers love name capturing). Moreover, the detection of name capturing is done very efficiently in Enchilada.

Enchilada macros bind with numbers and lists but not with other macros or operators. But because Enchilada lists hold expressions, macros can be indirectly bound to other macros.

Here is a simple (postfix) Enchilada macro:

5 3 {a b=b a - +}
5 {a=3 a - +}
3 5 - +
3 _5 +
_2

macro variables have lexical scope:

1 2 3 {a={b={c=a b c}}}
1 2 {b={c=3 b c}}
1 {c=3 2 c}
3 2 1

macros can be reduced eagerly:

[1] [2] [3] {a b c==[a] b [c] + +}
[1] [2] [3] {a b c==[a] b [c] + +}
[1] [2] {a b==[a] b [[3]] + +}
[1] {a==[a;2;[3]]}
[[1];2;[3]]

and name clashes are avoided by automatic alpha-conversion:

1 2 {a==[a] {a b=a b}}
1 2 {a=={aa=aa [a]}}
1 {aa=aa [2]}
1 [2]

passing and lifting(^) a macro into another macro:

1 2 [{a b==b a}] {d e f==[d] [e] f ^}
1 2 [{a b==b a}] {d e f==[d] [e] f ^}
1 2 {d e==[e] [d]}
1 {d==[2] [d]}
[2] [1]

Enchilada started as a language similar in design to the Joy language. But I think with macros on board it boosts the expressive power of Lisp.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

with macros on board

You should say "Enchilada macros" or "postfix lambdas" as to avoid confusion with Lisp macros.

What is the rule for the following equivalence?

1 2 {a==[a] {a b=a b}}
1 2 {a=={aa=aa [a]}}

(I am not sure I understand the position of [a] in the second line)

In the example above, the local a hides the a defined earlier. I am not familiar with name capturing issues in Lisp, what is different with Enchilada?

Don't want to confuse

I don't want to confuse you or anybody else with Enchilada speak. Next to that, my reply is somewhat late, but here it is nonetheless:

To explain [a]: here is a simple Enchilada rule: a monadic operator reduces when it's preceded by a list operand (a list is enclosed by square brackets).

An Enchilada macro is a special monadic operator, so:

[a] {b=b b}

reduces to:

[a] [a]

The previous example can't be. There can be no free variables in a top level Enchilada expression: variables can only 'live' within macros. Now if we would ignore name capturing (as in Lisp), reducing the following expression:

{a==[a] {a b==a b}}

would give us:

{a=={a=a [a]}}

Now if we prefix this expression with two number operands (a number is also a list in Enchilada) and reduce, we get:

1 2 {a=={a=a [a]}}
1 [1]

.. but we rather would like to have:

1 2 {a=={aa=aa [a]}}
2 [1]