Mark Wooding wrote:
Steven D'Aprano <ste...@remove.this.cybersource.com.au> wrote:
>
On the one hand, some people (me and possibly rurpy) consider "this is pass-by-foo" to be a statement about behaviour directly visible to the programmer. We have a set of behavioral traits in mind, and if a language exhibits those behaviours, then it is clearly and obviously pass-by-foo no matter how that behaviour is implemented. I'll call these the behaviorists.

Here's the problem.  I think I'm in that camp too!

I'm going to move away from the formal semantics stuff and try a
different tack.  Here's what I think is the defining property of
pass-by-value (distilled from the formal approach I described earlier,
but shorn of the symbolism):

  The callee's parameters are /new variables/, initialized /as if by
  assignment/ from the values of caller's argument expressions.
>
My soundbite definition for pass-by-reference is this:

  The callee's parameters are merely /new names/ for the caller's
  argument variables -- as far as that makes sense.

There's a caveat there for argument expressions which don't correspond
directly to variables -- and I've glossed over the issue of lvalue
expressions which designate locations and all of that.

Greetings, Mark!

A little background on myself, hopefully making my soon-to-follow question less idiotic.

I've been in the PC world for 20+ years now, and dabbled with programming through much of that time. I've written small utilities in Assembly (x86) and CL (AS/400), I just recently wrote a dbf module for python, and I've studied (in and out of the classroom) C, Fortran, Pascal, Java, Perl, Php, and Basic.

While I have had some formal training, my degree is in Business (long story -- I would rather have done CS), and much of your explanation in previous posts was waaaaay over my head.

I am in complete agreement with Steven's description of the behaviorist point of view for pass-by-value and pass-by-reference, and if asked I would say Python is pass-by-object. I offer this so you know where I'm coming from, not from any hostile motive.

I was hoping you might be able to clarify those last two sound bites for me -- I think I understand what you are saying, but I'm confused about how they relate to Python...

Specifically, how is a new name (pbr) different, in Python, from a new name initialized as if by assignment (pbv)? It seems to me than you end up with the same thing in either case (in Python, at least), making the distinction non-existent.

def func(bar):
    bar.pop()

Pass-by-reference:
  foo = ['Ethan','Furman']
  func(foo)                     # bar = foo

Pass-by-value:
  foo = ['Python','Rocks!']
  func(foo)                     # bar is new name for foo
                                # is this any different from above?

If I have this right, in both cases foo will be reduced to a single-item list after func. Any further explanation you care to provide will be greatly appreciated!

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to