«« Next » « Previous
«« Next » « Previous

Link Details

Announcement

iPhone DZone: Fresh Links On Your iPhone by matt at Sat Jul 05 14:09:51 EDT 2008

Reading DZone on your iPhone just got a little bit easier. Visit http://dzone.com/iphone from your iPhone to try out our beta iPhone support. You can view stories, filter by tags, and login. We'd appreciate your feedback at feedback@dzone.com.

DZone depends on you. Login and vote now.
Link 55866 thumbnail

By jober
via artfulcode.nfshost.com
Published: Dec 05 2007 / 14:54

Currying, known in Python land as partial application, is a technique in which a function taking multiple arguments composes a function that takes fewer arguments (in most languages, reducing to one, although this is not the case in Python) by partially applying it to given parameters. For example, a function, sum, might be used to compose a new function called "plus_one" by currying it with the value of one. The composed function is not evaluated; it is returned as a function object which may then be applied to other parameters.
  • 14
  • 0
  • 1052
  • 215

Comments

Add your comment
User 204981 avatar

reido56 replied ago:

0 votes Vote down Vote up Reply

The Javascript example doesn't appear to do what the blog says it does. Test code:

function curry(fn, scope) {
var scope = scope || window;
var args = [];
for (var i=2, len = arguments.length; i < len; ++i) {
args.push(arguments[i]);
};
return function() {
fn.apply(scope, args);
};
}
function alertTwoArg(firstArg,secondArg) {
alert(firstArg + ',' + secondArg);
}
var oneCur = curry(alertTwoArg,window,"firsty");
var twoCur = curry(oneCur,window,"secondy");
twoCur();

User 204981 avatar

reido56 replied ago:

0 votes Vote down Vote up Reply

Blog has been updated.

User 253983 avatar

jober replied ago:

0 votes Vote down Vote up Reply

Thanks for pointing out the problem with the function!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (14)



Voters Against This Link (0)