apoch / epoch-language

Home of the Epoch Programming Language Project
Other
72 stars 3 forks source link

Lexical closures and lambdas #138

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 don.ap...@gmail.com on 15 Feb 2012 at 8:30

GoogleCodeExporter commented 9 years ago
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 ryoohki@gmail.com on 15 Feb 2012 at 8:48