apoch / epoch-language

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

Partial function application #136

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What it says on the tin.

Possible syntax could look like:

multiply : integer a, integer b -> integer c = 0
{
    c = a * b
}

entrypoint :
{
    var multiply_by_five = multiply(5, _)

    print(multiply_by_five(2))    // prints 10
}

I'm not dead set on the underscore syntax, so feel free to make suggestions.

Original issue reported on code.google.com by don.ap...@gmail.com on 15 Feb 2012 at 8:20

GoogleCodeExporter commented 9 years ago
The problem with _ is that its kind of confusing, imo.

Also, how would you deal with something like:
var do_something_with_many_numbers = multiply_evens_add_odds(5, _, 6, _, _, 
999, _)

Not a very realistic example, mind you, but it gets the point across.. this 
would obviously translate into some function
do_something_with_many_numbers : integer a, integer b, integer c, integer d -> 
integer r = 0
{
    r = multiply_evens_add_odds(5, a, 6, b, c, 999, d)
}

But what if you wanted to re-order the function parameters? Not very easily 
done unless you manually wrap the function up.

A syntax using _<N>, N > 0 placeholders would work though:
var do_something = run_database_query(_2, connection, _1)
run_database_query("SELECT * FROM users WHERE 1", DbQueryType.DynamicSql)

Original comment by ryoohki@gmail.com on 15 Feb 2012 at 8:26