epoch-language
epoch-language copied to clipboard
Lexical closures and lambdas
Make stuff like this possible:
functiontype counter : -> integer count
count_from : integer start -> counter ret = lambda(count = ++start)
entrypoint :
{
counter alpha = count_from(0)
counter beta = count_from(100)
print(alpha()) // Prints 1
print(alpha()) // Prints 2
print(beta()) // Prints 101
}
While we're on the subject, come up with a better syntax for defining function
signatures (i.e. the "functiontype" cruft above).
As a matter of fact, the whole thing could use some polishing and mulling over.
Original issue reported on code.google.com by [email protected] on 15 Feb 2012 at 8:30
function counter = : -> integer count
function add = integer a, integer b - > integer c
entrypoint:
{
integer start = 100
add adder = lambda { c = a * b }
counter = lambda { count = ++start }
print(counter()) //prints 101
print(adder(1, 5)) //prints 5
print(adder(counter(), counter()); //prints 205
}
Original comment by [email protected] on 15 Feb 2012 at 8:48