[IronPython] IronPython 1.0 Beta 3 Released!

Dino Viehland dinov at exchange.microsoft.com
Tue Feb 21 17:28:57 PST 2006


Not sure if our wires are getting crossed here or what (there's a separate implicit cast thread somewhere else I thought, but anyway...)

Implicit casts should actually happen implicitly though - you shouldn?t need any syntax to cause them to happen.  The closest thing I could find in CPython to an implicit cast was __coerce__ for numeric methods, but it has rather strange semantics compared to what we want here.

In C# if you define an implict cast:

    public class A {
        public A(int value) {
            this.value = value;
        }

        public int value;

        public static implicit operator B(A a) {
            return new B(a.value);
        }
    }

You can then do:

B xyz = A(5); 

And it compiles and the C# calls the implicit cast under the covers.  If you did an explicit cast instead you would indeed need to add the cast:

B xyz = (B)A(5);

Otherwise it wouldn't compile.

I think a good syntax for the explicit cast might just be object creation like:

xyz = B(A(5))

which is similar in many respects to:

a = int('23')

although then there'd probably be issues w/ a class that defines both a constructor & an explicit cast, so this is more complex than implicit casts (for implicit casts we can just fall back to checking for op_Implicit on the type as the last step of our conversion efforts, so it fits in nicely).



Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ernst, Nathan
Sent: Tuesday, February 21, 2006 5:13 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython 1.0 Beta 3 Released!

Perhaps this is just an appropriate place for an overload of super?

Not having tried it, I can't comment on whether or not this will work.
But, rather than adding a new syntax for an "implicit" cast, the
python-ish way of doing this would seem to be to force an explicit
"cast" using super.

In C#, wouldn't you be required to issue an explicit cast to invoke the
member? Why in IronPython should it be any different?  My $.02

-Nathan Ernst

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: Tuesday, February 21, 2006 3:07 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython 1.0 Beta 3 Released!

I think you're right about needing to throw here.  I'll get that fixed
for the next beta.  AssemblyName's are an interesting idea, but I wonder
if anyone will ever get an assembly name too.  

I think it's probably best to stay away from that until we know of a
scenario where this actually makes a difference.  If someone really
needs to interact that deeply w/ CLR loading they can always fall back
to giving us the raw assembly object after doing an
Assembly.Load(AssemblyName).  But I'd rather add the feature later than
have some useless dead code lingering around forever :).


Do you want to help develop Dynamic languages on CLR?
(http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE
-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of J. Merrill
Sent: Tuesday, February 21, 2006 12:50 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython 1.0 Beta 3 Released!

Shouldn't the function below raise an exception if the object holds
neither an assemnbly nor a string?  Silence should not be a translation
of "we ignored what you passed in because it was not an expected type"
!!

(Should there perhaps be another block supporting reference being an
AssemblyName?  I don't know where a Python programmer would get one,
however.)

At 12:36 PM 2/16/2006, Dino Viehland wrote (in part)
>[snip]
>Unfortunately then you'll start hitting the stack overflow bug that Jon
reported.  His fix is close to being right, but really it should become:
>
>        private void AddReference(object reference) {
>            Assembly asmRef = reference as Assembly;
>            if (asmRef != null) {
>                AddReference(asmRef);
>                return;
>            }
>
>            string strRef = reference as string;
>            if (strRef != null) {
>                AddReference(strRef);
>                return;
>            }
>        }
>[snip]




J. Merrill / Analytical Software Corp

_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


More information about the users mailing list