FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Should we keep delegates?

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Tue Mar 27, 2007 8:25 pm    Post subject: Should we keep delegates? Reply with quote

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
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Apr 02, 2007 10:09 pm    Post subject: Reply with quote

Well they're gone.
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Tue Apr 03, 2007 7:32 am    Post subject: Reply with quote

One thing that I failed to mention, but thought I had, and apparently misremembered, ... etc. Smile 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
View user's profile Send private message AIM Address Yahoo Messenger
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Tue Apr 03, 2007 8:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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