View previous topic :: View next topic |
Author |
Message |
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Mar 27, 2007 8:25 pm Post subject: Should we keep delegates? |
|
|
Revising some of the API and standard libraries, I've come to wonder how useful delegates are. When I came up with them, I thought they were a neat idea, but now I kind of wonder. They're kind of "second-class" compared to regular functions, as they can't really be used most places where functions can. This is mostly because they're more complicated to call than functions, and most places where you need a function (like for metamethods), using a delegate doesn't make much sense.
Not being someone who uses MiniD that much, I'd be interested to know from those who do use it: should we keep delegates or not? Or rather, if I were to remove them, would you be okay with using closures to take their place, like so:
Code: | function curry(func, param)
{
return function(vararg)
{
return func(param, vararg);
};
}
function foo(a, b)
{
writefln("foo: ", a, ", ", b);
}
foo(4, 5);
local dg = curry(foo, 9);
dg(6); |
? |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Apr 02, 2007 10:09 pm Post subject: |
|
|
Well they're gone. |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Tue Apr 03, 2007 7:32 am Post subject: |
|
|
One thing that I failed to mention, but thought I had, and apparently misremembered, ... etc. Such a basic-case curry'ing function should probably make an appearance in the baselib if its to be the standard way. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Apr 03, 2007 8:01 am Post subject: |
|
|
Hm. That might be trickier than it seems. Well, I mean, it would certainly be possible, but the advantage of doing it entirely in MiniD code is that the returned curried function will perform a tailcall of the original function, improving performance somewhat. Whereas if the curry function were implemented natively, it would impose an extra call depth for each curried parameter. Though, I wonder how much that would matter since it would be written in native code, which is much faster..
I guess it wouldn't hurt to put it in. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|