[IronPython] DLR and Iron* language types

Dino Viehland dinov at exchange.microsoft.com
Tue Sep 25 19:46:11 CEST 2007

Ruby hash and Python dictionary should interop just fine because Ruby's hash will be an IDictionary and Python's dictionary will also be an IDictionary.  Therefore we'll be able to recognize the interface methods and dispatch to them appropriately.  We don't currently support extension methods on interfaces (we have a bug to fix that) but when we do IDictionary will get methods like keys from Python so even the normal dictionary methods will be properly exposed.  But it looks like Ruby's hash method is currently a subclass of Dictionary<object, object> so I think you'll probably get a great level of interop today.

But what might be more interesting is a user defined dictionary-like object.  For this we'll end up getting all the rules directly through an IDynamicObject instead of the default binder and/or derived binders.  The parts of this that Python could consume today are:

        del d["bar"]
    d["meaning of life"] = 42

That will work through DoOperationAction(Operators.GetItem)/DOA(Op.DelItem)/DOA(Op.SetItem).  We have a "Contains" operator in our Operators enum but we don't yet use it for language interop.  Once we start implementing that then the 'if "bar" in d' would also be consumable from Python.  The .keys call is unlikely to ever work though.  You'll need to call whatever the Ruby equivalent of .keys is.  If it happens to be .keys then it'll work.

Now you may have noticed that I said Python could consume objects from another language using these characteristics.  I don't believe Ruby objects have an IDynamicObject implementation of sufficient fidelity to make this happen yet.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Lee Culver
Sent: Tuesday, September 25, 2007 10:33 AM
To: users at lists.ironpython.com
Subject: [IronPython] DLR and Iron* language types

Both Ruby and Python have concepts of lists and dictionaries (though I think ruby calls them something different, and the details of how they are used are a bit different as well).  Is the DLR going to (eventually) support passing these objects between each other?

For example, let's say I have a piece of IronPython code as follows:

def foo(d):
    "d is a dictionary"
    if "bar" in d:
        del d["bar"]
    d["meaning of life"] = 42
    keys = d.keys()

    # call other dictionary functions on d here
    # ...
    # when this function returns, the Ruby hash object this
    # function was called with has been updated

Can I call into this function, from IronRuby, with the Ruby equivalent of a dictionary (I think that's a "hash" if I'm not mistaken) and have that hash updated as the "foo" method suggests?

I would imagine, from a programmer's perspective, that even though the Ruby hash class has different functions, it's basically the same thing as the Python dictionary.  When you call into one language with the other's "equivalent objects" does the other language see it as their own type.

My question is, do you plan on supporting this type of functionality in the DLR and the Iron* languages?  If so, is that support implemented "now" (meaning when IronRuby is released will it support it)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070925/07b925bb/attachment.html>

More information about the Ironpython-users mailing list