Hi all, On Thu, Dec 18, 2008 at 16:07, Bob Ippolito <b...@redivi.com> wrote: > I'm not a real big fan of currying in languages where it's not > built-in. It's easy to make a mistake by calling a function with too > few arguments and you get a harder to track down bug. It also doesn't > work well with languages that have default arguments or the equivalent > (e.g. using the arguments object) because you don't know exactly when > to stop currying.
Actually, the functions I proposed (curry and uncurry, stolen form Haskell) do not describe this kind of currying. curry takes a function of one argument, a tuple, and returns a modified function that instead takes N arguments (the elements of the tuple). The reason for the name curry is that it basically performs the translation you (Bob) mentioned in Haskell, i.e. it transforms an N argument function to a nesting of N one-argument functions, i.e. it "curries" the function. uncurry takes a function of N arguments and returns a modified function that instead takes one argument, a tuple of N elements. Obviously the naming comes from this being the reverse of curry. The absolute main use case is mapping functions over a list of tuples (in js list=tuple). This uses uncurry to change a function f(a,b) to f(t) where t is a tuble of a and b. That way you can simply map (or filter) the function over the outer list and arguments get placed in the correct spot. Currying is a convenience for changing a function that takes a tuple (i.e. a list in js) and apply it with the tuple elements as arguments -- i.e. exactly what Function.apply does in js. I'd still include it if uncurry is included, for the sake of symmetry. I do realize this might be a bit too eccentric -- but it is the kind of thing that becomes very useful to grab when you do a lot of functional-style programming in any language. Per provided bind("apply", operator.add, null) as equivalent to uncurry. This is true, except that the context (this) is not maintained.. but yes, maybe it is my weird style but I'd give an alias to this. Dunno.. I'm happy to keep it in my personal library of helper functions :) cheers, Arnar --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MochiKit" group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to mochikit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~----------~----~----~----~------~----~------~--~---