nonlocal fails ?

Luciano Ramalho luciano at ramalho.org
Fri Nov 15 14:15:57 EST 2019


Re: the whole pass by reference discussion.

I've seen Python's argument passing described as "call by value,
except that all values are references". This makes sense, but is
confusing.

Michael Scott, in his textbook Programming Language Pragmatics (4e)
terms the Python way "call by sharing". That is the same mode used in
most OO languages that don't have pointers, including Ruby, SmallTalk,
and Java (this applies to Java reference types; primitive types use
call by value). Call by sharing means that each formal parameter of
the function gets a copy of each reference in the arguments.

Cheers,

Luciano


On Fri, Nov 15, 2019 at 3:58 PM Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>
> On Fri, 15 Nov 2019 11:54:50 -0500, Richard Damon
> <Richard at Damon-Family.org> declaimed the following:
>
> >
> >I remember in early FORTRAN being able to do something like this (its
> >been years since I have done this so syntax is probably a bit off)
> >
> >
> >
> >foo(1)
> >
> >and after that if you did
> >
> >j = 1
> >
> >then now j might have the value 2 as the constant 1 was changed to the
> >value 2 (this can cause great confusion)
> >
>
>         It was a very early FORTRAN that did that, since literals were stored
> in general R/W memory and the address was passed. Later FORTRAN compilers
> would flag a section of memory for R/O and stored literals in that section
> -- so attempts at modification would result in an error.
>
> >later I believe they added the ability to specify by value and by
> >reference, and you weren't allowed to pass constants by reference,
>
>         Many compilers added extensions for interfacing to other languages (DEC
> is famous for %val(), %ref(), %descr() for controlling parameters, and
> %loc() external to parameters. %ref wasn't really useful in FORTRAN since
> that is the native method. %loc returned the address of the target item.
> %descr was a weird one -- things like character strings were passed by
> descriptor: first word was the address [standard reference model], second
> word encapsulated information like the length allocated to the string [not
> the length used, but the size of the memory allocation].
>
>         Literals were still passed by reference -- just to read-only memory
> block. Otherwise the called function wouldn't know how to behave!
>
> subroutine xyz(parm)
> integer parm
>
> ...
>
> call xyz(1)
> call xyz(abc)
>
> if the first was passed by value and the second by reference, what was
> "parm" in the called function to do
>
>
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|     http://shop.oreilly.com/product/0636920032519.do
|  Technical Principal at ThoughtWorks
|  Twitter: @ramalhoorg


More information about the Python-list mailing list