epoch-language
epoch-language copied to clipboard
Partial function application
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 [email protected] on 15 Feb 2012 at 8:20
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 [email protected] on 15 Feb 2012 at 8:26