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

**URL:** <https://rubytalk.org/t/partial-function-application-was-re-binding-precedence-for-first-sym/16177>\
**Category:** ruby-talk\
**Created:** [1 February 2005 05:51 UTC](https://rubytalk.org/t/partial-function-application-was-re-binding-precedence-for-first-sym/16177 "2005-02-01T05:51:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![E\_S](https://avatars.discourse-cdn.com/v4/letter/e/3be4f8/32.png) [@E\_S](https://rubytalk.org/u/E_S)\
**Post date:** [1 February 2005 05:51 UTC](https://rubytalk.org/t/partial-function-application-was-re-binding-precedence-for-first-sym/16177/1 "2005-02-01T05:51:23Z")

</div>

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 🙂 I have  
> never noticed these other names for it before.
> 
> > def fun(x, y, z)  
> > q = x + y + z  
> > end
> > 
> > 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  
> > end
> > 
> > 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  
> > end
> > 
> > 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  
> end

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,
> 
> would
> 
> > 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 🙂
> 
> I am for it. Much more so then for my silly symbol notation 😉
> 
> T

E

---

<div class="post-metadata">

**Author:** ![Matt\_Maycock](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@Matt\_Maycock](https://rubytalk.org/u/Matt_Maycock)\
**Post date:** [1 February 2005 06:04 UTC](https://rubytalk.org/t/partial-function-application-was-re-binding-precedence-for-first-sym/16177/2 "2005-02-01T06:04:26Z")

</div>

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

[http://www.cs.drexel.edu/~ummaycoc/curry.rb](http://www.cs.drexel.edu/~ummaycoc/curry.rb)

May the force be with you.

~Me!

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

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [1 February 2005 06:20 UTC](https://rubytalk.org/t/partial-function-application-was-re-binding-precedence-for-first-sym/16177/3 "2005-02-01T06:20:45Z")

</div>

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).

T
