[Ironruby-core] Delegates (agian)

Dino Viehland dinov at exchange.microsoft.com
Thu Oct 25 18:11:28 EDT 2007

At the DLR level we can basically convert any callable object into a delegate.  This is done by creating a dynamic method (that matches the delegates signature) that contains an embedded DynamicSite which performs a CallAction.  That call action works through our IDynamicObject implementations (for complex language defined types), through language specific binders (Python wants to make newable-things callable), or through the base binder which provides the implementation for known type-systems (CLR types, COM types in the future, maybe IReflect/IExpando in the future?).

So anything can be a delegate (it just might throw at call time)!

(you might see 2 of these, I don't think rubyforge liked my e-mail address before)

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dermot Hogan
Sent: Thursday, October 25, 2007 2:51 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Delegates (agian)

> I don't think we need RubyDelegate, you can write
> x << method(:y)
> x << C.instance_method(:y).bind(obj)
> or
> x += method(:y)
> x += C.instance_method(:y).bind(obj)
> x -= method(:y)
> if you will.
> Blocks/procs should also work:
> x { puts 'on click' }
> x << lambda { puts 'on click' }
> Tomas

This isn't really what I mean. You need to be able to provide
*syntactically* a delegate reference.

So in C#, we have x += new EventHandler(mymethod)

and in VB (I'm a bit rusty but something like this):

x += new EventHandler(AddressOf mymethod)

it's not the same as adding a method to an object. The object already
*has* the method. What you need to to do is add the *delegate* (a
typesafe function pointer) into the delegate chain.

I'm not an expert in any way in what you are doing in the DLR, but it
doesn't seem to me that this does it. A delegate is a different thing
from a method object. 'method' returns a method object which isn't the
same as a delegate (an instance of the Delegate class) - at least, I
can't add it into the delegate chain with the current version of IR.

Are you saying that 'method' will return a delegate? I'm not clear on
this at all.

Posted via http://www.ruby-forum.com/.
Ironruby-core mailing list
Ironruby-core at rubyforge.org

More information about the Ironruby-core mailing list