Description
openedon Mar 9, 2012
I idea is relative simple, most languages lack it, but it's awesome and quite easy to be integrated I guess...
This example is obvious: ((x,y) -> x + y)(1,2)
When calling with only one parameter as ((x,y) -> x + y)(1)
it raises a wrong number of arguments error. When a function is called with too few arguments it should instead return a anonymous function expecting the a missing one and executing it. So ((x,y) -> x +y)(1)
should return (a -> ((x,y) -> x +y)(1,a)) )
(x,y) -> x +y is simply +(x,y). So +(1) would become (a -> +(1,a)). This function increments. Incrementing all fields of an array would be map(+(1),[1,2,3,4]).
Of course it would be possible to simply create an anonymous function that increments, but that it would be cool if that happed automagical. Sometimes this aids a strange but useful programming style.
# could become a library function.
function >>=(a,b)
if a
b(a)
end
end
function reportError(category::String, message::String)
# write errors to different files, maybe send emails.
end
# so some stuff that might fail
data=f(data)
>>=(checkData(data),reportError("serve"))
That a way more beautiful than
>>=(checkData(data),(message -> reportError("serve", message)))
as a consequence (if f is a regular function expecting 3 parameters) f(1,2,3)
would be as valid as f(1,2)(3)
or f(1)(2)(3)