[IronPython] Array Access Problem

Jim Hugunin jimhug at exchange.microsoft.com
Wed May 11 07:26:59 CEST 2005

Timothy Fitz wrote:
> On 5/10/05, Jim Hugunin <jimhug at exchange.microsoft.com> wrote:
> > >>> apt[0].X = 0
> > If value types were immutable this would throw.  The exception
> > might give people enough information to get started tracking down
> > issue and modifying their code to work correctly.
> I want to say this should be equivelant to
> apt[0] = Point(0, apt[0].Y)
> which would not break mutability issues. However this breaks with the
> current python trend (tuples could provide this functionality, but
> don't).

Because of the way that value types work, there's no difference between
the results of
  apt[0].X = 0    and   apt[0] = Point(0, apt[0].Y)

The big question is how important it is that both of the following are
  apt[0].X = 0    and    tmp = apt[0]; tmp.X = 0

These two are different for value types in C# and VB.  However, it's
pretty weird to think about them being different in Python.  It's easier
for me to imagine supporting the version on the left if the version on
the right will consistently throw claiming that tmp is immutable.  This
would still be confusing to people, but at least it would be very

> To me, making apt[0].X = 0 require an explicitly new object is a
> almost a showstopper. 

I'm not willing to go that far.  It's a pretty rare case that you need
to work with arrays of mutable value types with using CLS libraries.
And the beauty of Python is that it's a great language for writing
little helper routines to make the painful painless when needed.

> Are there any other purely reference semantic
> languages on the CLI? Or are we treading on new ground?

That's a great question.  I'm pretty sure that both J# and Jscript from
MS have pure reference semantics and I'm sure there must be many other
languages with this dilemma.  I don't know what solutions other people
have come up with.  Does anyone else out there know?  Has someone tried
this in J# or Jscript to see how arrays of value types behave?

Thanks - Jim

More information about the Ironpython-users mailing list