[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: assignment, reference, += and parameter passing

The semantics of "+=" don't have this possible ambiguity in Smalltalk
because "+=" is not a special operator. I.e., everything is a message
and any message can be defined/redefined at any time by an implementor
(or dynamically in a running system since the compiler is typically
always available to recompile methods -- which is effectively how
eval-works with anonymous/unbound methods).

    Method behavior: AnyClassOrInterfaceIWant [
    += anArg
        "do whatever I want, cuz this is just a method"

-- Dave S. [SmallScript LLC]

SmallScript for the AOS & .NET Platforms
David.Simmons@SmallScript.com | http://www.smallscript.org

> -----Original Message-----
> From: owner-ll1-discuss@ai.mit.edu
> On Behalf Of Justin Sheehy
> Sent: Tuesday, December 18, 2001 8:21 PM
> To: Pixel
> Cc: ll1-discuss@ai.mit.edu
> Subject: Re: assignment, reference, += and parameter passing
> Pixel <pixel@mandrakesoft.com> writes:
> > Python
> >   pass-by-ref except for numbers and strings
> You misunderstand Python's assignment and parameter passing model.
> It is always "pass by object reference".
> All names are bound to object references.  Parameters are
> bound by object references.  The value in the object has absolutely
> nothing to do with this.  In this way "=" and parameter passing are
> basically equivalent.
> Numbers and strings are passed in exactly the same way as are lists,
> class instances, or anything else.  They are simply the content of an
> object that is being referenced.
> The source of your confusion may be that "=" and "+=" operate in a
> very different way from each other.  (In my opinion "+=" should not
> have been added, precisely because of this confusion.)
> a = b
>   This always binds a to refer to the same object as b.
> def f(x):
>     do something with x
> f(a)
>   This always binds x to refer to the same object as a, regardless of
>   the type of the value in that object.
> a += b
>   This is a bit funny.  Generally, if a refers to a mutable object
>   as a list, this modifies the existing object that a refers to.  If a
>   refers to an immutable object such as an int, this rebinds a to
>   refer to a new object obtained by adding a and b.
> -Justin