By value or by reference?
Alex Martelli
aleaxit at yahoo.com
Tue Oct 19 15:45:21 EDT 2004
Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
...
> Here's a program that tells you the answer. Should be trivially
> translatable to many other languages.
>
> ========================================================================
> def passCheck(b):
> b = 'new'
>
> def doesThisLanguageBindByValue(language):
> a = 'original'
> b = a
> b = 'new'
> if a == 'original':
> print "%s assigns by value" % (language)
> else:
> print "%s does not assigns by value" % (language)
Can you give some examples of languages which would end up in the else
branch? I think that with a suitably perverse operator= I might be able
to imitate this weird effect in C++, but then I think I'd have to make
the 'b = a' a copy ctor instead of an assignment (or get to such levels
of perversion that even my once-C++-addled mind reels at...;-).
Alex
More information about the Python-list
mailing list