A question on modification of a list via a function invocation
Rustom Mody
rustompmody at gmail.com
Mon Sep 4 06:27:49 EDT 2017
On Monday, September 4, 2017 at 3:35:54 PM UTC+5:30, Antoon Pardon wrote:
> Op 04-09-17 om 00:44 schreef Dennis Lee Bieber:
> > And is a limited theoretical study, heavy in mathematics and light in
> > implementation.
> >
> > Programming Languages: Design and Implementation (Terrence W Pratt,
> > 1975, Prentice-Hall) has a whole section (6-9 Subprograms with Parameters:
> > Parameter Transmission Techniques)...
> >
> > """
> > Basic parameter Transmission Techniques
> >
> > Transmission by Value: ... the actual parameter is evaluated at the point
> > of call. The /values/ of the actual parameter is then transmitted to the
> > subprogram and becomes the initial value associated with the corresponding
> > formal parameter. ...
> >
> > Transmission by Reference (Location or Simple Name): In transmission by
> > reference a pointer is transmitted, usually a pointer to a data location
> > containing the value. ... Any assignment to Y in SUB will change the value
> > of X back in the calling program.
>
> IMO that depends on the semantics of the assignment statement. In an environment
> where an assignment copies the value into the object the variable points to, this
> is correct. However if assignment provides a new object that is now bound to the
> variable, it is incorrect.
>
> The diagram below tries to illustrate the two different assignment semantics:
>
> BEFORE
> +-----+ +-----+
> | | | |
> | 5 | | 7 |
> | | | |
> +-----+ +-----+
>
> ^ ^
> | |
> <x> <y>
>
>
> x = y
> AFTER
>
> C style | Python style
> |
> +-----+ +-----+ | +-----+
> | | | | | | |
> | 7 | | 7 | | | 7 |
> | | | | | ---> | |
> +-----+ +-----+ | / +-----+
> /
> ^ ^ / ^
> | | / |
> <x> <y> <x> <y>
That's fine as far as it goes
But then you have people (Steven above) who feel that python passing has
no exceptions (in parameter passing)
Does a poor job AFAIAC of explaining the difference between foo and bar in foll
>>> def foo(x): x += 2
>>> def bar(x): x.append(2)
>>> a=10
>>> b=[10]
>>> foo(a)
>>> a
10
>>> bar(b)
>>> b
[10, 2]
>>>
More information about the Python-list
mailing list