There are some situations when you can only pass a variable referring
to a function; with a curry function you can pass a variable that
refers to a function + arguments.
A problem, though, is that some curry functions seem to go a little
beyond this basic functionality, behaving differently with different
numbers of arguments. (I'm thinking of the dojo curry function,
which is based on one from a certain language.) I don't follow it
exactly when it does this, but it makes me leery of using it.
On Apr 17, 2007, at 6:38 PM, Nathan Young -X ((natyoung - Artizen at
Cisco)) wrote:
Hi.
Can you describe a problem whose solution becomes much easier by
using currying?
----->Nathan
From: jquery-en@googlegroups.com [mailto:jquery-
[EMAIL PROTECTED] On Behalf Of Sean Catchpole
Sent: Monday, April 16, 2007 8:17 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Library showdowns
Jeffrey and Glen,
Allow me to explain currying. Imagine if you will the following
function (written in javascript)
add = function (a,b) { return a+b }
I can now call add(3,7) and it will return 10.
A language that allows currying would allow me to pass only one
variable and it would return a new function that takes a single
variable. ex: add(3) would return a function that adds three to the
input. Here is an example way of implementing it in javascript:
add = function (a) { return function (b) { return a+b } }
Now I can call add(3) and it will return function (b) { return 3+b }
In the same sense as the first example we can now call add(3)(7)
and it will return 10.
This allows for lots of cleverness in use of functions and
ultimately make functions far more reusable. I consider it a great
advantage of functional programming. So as you can see, the same
effect can be created, but it's tedious. I'm trying to come up with
a trickier way so that it's not so painful to create a curried
function in javascript.
~Sean