[IronPython] Plans for overloads?

J. Merrill jvm_cop at spamcop.net
Wed Jul 20 01:00:55 CEST 2005


That looks like an excellent, and it seems to me quite elegant, solution.

What mechanism(s) do you plan to provide for .Net callers to see IronPython functions as "strongly typed" routines, should we want to do that?

At 05:45 PM 7/19/2005, Martin Maly wrote
>Hi,
>
>Last Friday I promised to send more information about the progress we
>are making with overloaded method resolution. The solution that we came
>up with (and it will be available in the nearest release) is based on
>the way IronPython uses generic types. Consider following code that
>instantiates generic List:
>
>from System.Collections.Generic import *
>x = List[str]()
>
>The index serves as a means to specify the type arguments for the
>generic type parameters.
>
>Similarily, consider method Console.WriteLine:
>
>>>> from System import *
>>>> print Console.WriteLine.__doc__
>System.Void WriteLine()
>System.Void WriteLine(bool)
>System.Void WriteLine(System.Char)
>System.Void WriteLine(System.Char[])
>System.Void WriteLine(System.Char[], int, int)
>System.Void WriteLine(System.Decimal)
>System.Void WriteLine(float)
>System.Void WriteLine(System.Single)
>System.Void WriteLine(int)
>System.Void WriteLine(System.UInt32)
>System.Void WriteLine(long)
>System.Void WriteLine(System.UInt64)
>System.Void WriteLine(object)
>System.Void WriteLine(str)
>System.Void WriteLine(str, object)
>System.Void WriteLine(str, object, object)
>System.Void WriteLine(str, object, object, object)
>System.Void WriteLine(str, object, object, object, object)
>System.Void WriteLine(str, System.Object[])
>
>We can use indexing to select the specific method from the overloads.
>For example:
>
>>>> Console.WriteLine[str]("Hi")
>Hi
>>>> Console.WriteLine[Single](3.5)
>3.5
>>>> Console.WriteLine[int]("Hi")
>IronPython.Objects.PythonValueError: Bad args for the method <method#
>WriteLine on System.Console>
>>>> print Console.WriteLine[UInt64].__doc__
>System.Void WriteLine(System.UInt64)
>
>The simple types are quite straightforward. With array and byref
>parameters, things get little more complicated because IronPython
>doesn't have syntax for expressing the array or byref types simply. To
>create array or byref types, use Type.MakeArrayType and
>Type.MakeByRefType, for example:
>
>>>> print Console.WriteLine[Type.MakeArrayType(Char)].__doc__
>System.Void WriteLine(System.Char[])
>>>> print Double.TryParse[str, Type.MakeByRefType(Double)].__doc__
>bool TryParse(str, System.Double&)
>>>> Double.TryParse[str, Type.MakeByRefType(Double)]("3.5")
>(True, 3.5)
>
>Martin
>[snip]


J. Merrill / Analytical Software Corp




More information about the Ironpython-users mailing list