Guide to the python interp. source?

Alex Martelli aleax at aleax.it
Sat Jul 27 11:01:20 EDT 2002


Tim Gahnström /Bladerman wrote:
        ...
>> > Things I want to change is for example, everything should be "call by
>> > refferense",
>> That may be very hard.  If you want things like this:
>>
>> def f(x):
>>     x += 1
>>
>> i = 2
>> f(i)
>> i --> 3
>>
>> then you have problems.
> 
> That is exactly what I want to have, that is more intuitive I think and I
> don't think it must be that hard either. It is not a speed issue so it

It's hard to believe that you can hold such opinions if you
understand Python.  Or if you have really thought about the
issues, such as -- what happens when two or more arguments
are involved and interact?  E.g., they're the same variable,
or an index and an indexing that uses it, etc...?

def f(x, y):
  x = 23
  y = 45

and:

i = 7
f(i, g[i])

We understand that you keenly want i to be 23 as "more intuitive"
(I've never seen a programming beginner tackling Java or Python
as a first language expect that -- the "intuitiveness" appears to
come entirely from the way some OTHER languages behave:-), but
what should "intuitively" be the item of g that is affected?

In CBR languages, it's invariably g[7] that gets the 45, and THAT
baffles every beginner I've ever met.  Affecting g[23] would
be "call by NAME" and indeed very intuitive, but such a living
hell to implement that since Algol-60's demises I doubt any
language has gone down that route.


> must not be a true CBR. I will probably figure out some ugly hack to make
> it seem like CBR.
> Maybe look into value/copy return as Alex Martelli mentioned. What I want
> is not really CBR but the, from Ada known "in out parameters" or the
> Pascall "var parameter".

Ada and Pascal have value semantics.  x = y makes a COPY of the
stuff held in a "box" named y, into a "box" named x.  Python has
no boxes, it has post-it notes -- reference semantics.  That
changes everything...


Alex




More information about the Python-list mailing list