
Scott.Daniels at Acm
Apr 14, 2002, 2:32 PM
Post #3 of 4
(979 views)
Permalink
|
|
currying (was: Re: A trivial question about print)
[In reply to]
|
|
On Fri, 12 Apr 2002 23:50:27 +0000 (UTC), huaiyu [at] gauss (Huaiyu Zhu) wrote: > Jeremy Bowers <newsfroups [at] jerf> wrote: > >Has anyone done any work on creating a more general curry function? One > >that might for instance curry the second of three positional arguments? > >Using the above definitions: > >f2 = curry2(f, a, c) > >f2(b) > > In general you must have a way to indicate a subset. Like > g = curry([2, 3, 5], f, a1, a4, a6) > g(a2, a3, a5) > ... I had kind of thought that the keyword args would take care of this. Sure there are cases where this wouldn't be true, but I'd hate to have to read code that included ... curry([2, 3, 5], f, a1, a4, a6) ..., I'd have the devil's own time determining which args were specified. IMHO the real questions are (1) front or back (default last or first), and (2) call-time vs. curry-time keyword superceding. You of course know which I'd choose (the ones in the recipe). On issue (1), providing finals args back to front interferes with keyword args, so I'd forget that. Providing call-time before curry time in a "flexible" order is worse: you cannot read the curry-time args and know what is covered. I concede most programming styles leave the "fiddley" args -- perfect curry fodder -- at the end of the argument list. Even so, I'd prefer the earlier args be the curry args, since you more readily know what args are being consumed. I'd argue in favor of making those "fiddley" args keyword args. Issue (2) is more debatable: call-time seems to me more pythonic, but I can see logic for either side. The keyword stuff can be seen as setting defaults if call-time supercedes (which is useful in and of itself). More than anything else, this is what tips me in favor of call-supercedes-curry. Raising an exception on keyword conflict is another possibility, but this seems more like the strong typing / declared constants view: don't trust the user to do it right. Of course I'd love to see curry show up in the built-ins (I always forget to import it before I use it). As to Alex's comment on the recipe -- of course he's right; I just hadn't seen the possibility of curry by closure until nested scopes showed up after I had written curry. -Scott David Daniels Scott.Daniels [at] Acm
|