Partial function application (was: Re: Binding precedence for first sym...)

Trans wrote:

E S wrote:

Oh, I was serious. Partial function application (also referred to as
'macro binding' and 'currying') means that given a certain function
(or method), e.g.

Ah, forgive me! I have heared of curry. I like to eat it :slight_smile: I have
never noticed these other names for it before.

def fun(x, y, z)
q = x + y + z

If this function is invoked with a partial argument list, e.g.

fun 1, 2

Then, instead of throwing some sort of an error, the call would
produce a new function where the given arguments are bound.
Essentially, the previous call would yield:

def fun(z)
q = 1 + 2 + z

So these calls would be equal:

fun(1, 2, 3) # => 6
((fun 1, 2) 3) # => 6
fun(1, 2)(3) # => 6
x = fun(1, 2); x(3) # => 6

I highly regard this. It should be so.

The only problem would be handling the destructive updates, i.e. what

would happen if one tried to curry this with x:

def fun(x, y, z)
x = x + y + z

x can't be directly substituted since it's assigned to. It'd have to
be translated to 'xx = x + y + z' or something.

I do not see a problem. The x is local and has no functional baring.
The translation is simply:

fun(1,2) #=>

def fun(1, 2, z)
x = 1 + 2 + z

Maybe 'problem' is too strong a word. Let's say it's not altogether
straightforward: you can't just replace all instances of x in the
method body; can't replace in assignments and can't reuse after some
sort of an in-place modification (which should normally be denoted
with a !, but sometimes isn't). One could of course simply shelve the
responsibility to the coder but that's usually not the popular option.

This probably isn't something most Rubyists, at least initially,


be excited about but it's quite useful. I think it'd be possible to
implement as a library but it'd obviously be fairly slow. Of course
there's always Haskell :slight_smile:

I am for it. Much more so then for my silly symbol notation :wink:



Long ago, in a time of myth - the before time - I made this:

May the force be with you.



There's no word in the English language for what you do to a dead
thing to make it stop chasing you.

Yet, I think one could tackle the problem with a method probe. A
problem that does arsie is catching conditionals b/c they aren't real
methods (unfortunately).