[Tutor] beginning to code

Marko Rauhamaa marko at pacujo.net
Fri Sep 22 08:40:43 EDT 2017


ram at zedat.fu-berlin.de (Stefan Ram):

> Marko Rauhamaa <marko at pacujo.net> writes:
>>ram at zedat.fu-berlin.de (Stefan Ram):
>>>Marko Rauhamaa <marko at pacujo.net> writes:
>>>>swap(slot_ref(locals(), "x"), slot_ref(locals(), "y"))
>>>You need to be able to write the call as
>>>swap( x, y )
>>Why?
>
>   You responded to Bart:
>
> |     swap(x,y)
> |     print (x,y)             # "Z" and "10"
> |
> |If not, then it doesn't have reference passing as
> |it is normally understood.
>
>   , and Bart required this form. Moreover, if you allow other
>   forms, such as
>
> swap( &x, &y )
>
>   , then even C, would have "call by reference",
>   but it has not.

There's two things: syntax and semantics.

Obviously, Bart's syntax couldn't work syntactically unless Python added
the syntactic facilities. But the bigger question is a semantic one: is
it possible regardless of syntactic considerations.

As Chris pointed out, Python has explicitly ruled it out with the
immutability caveat to locals().


Marko



More information about the Python-list mailing list