On Mon, Sep 4, 2017 at 6:16 PM, Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote: > Chris Angelico wrote: >> >> This is another proof that you can't divide everything into "pass by >> value" vs "pass by reference" > > > True, but that doesn't mean you should deny that something > is pass-by-value when it actually is. > >> In C, a string is not an >> entity; it's simply an array of characters. Arrays are never passed by >> value; > > > I think it's more accurate to say that arrays are never > passed at all in C.
This is technically true; however, it's common to describe a function as "accepting a string" as a parameter. What it actually accepts is a pointer to char. Is that "passing an array by reference"? Not quite. Is it "passing a pointer by value"? Technically correct, but useless. Is it "passing a string by <anything>"? Technically incorrect, but probably more useful > A better name for pass-by-value would be "pass-by-assignment". > Passing a parameter by value is equivalent to assigning it > to a local name. That's true in Python too though - parameter passing is equivalent to assigning to a local name. And in C++, where you have actual references, a reference parameter is equivalent to initializing a local reference with the same result. I expect that "parameter passing is equivalent to assignment" is true in the bulk of languages. >> yet everything in C is passed by value. So you pass a >> pointer... by value. > > > Yes, because that's what happens when you assign an array > in C. > > If it seems screwy, it's because assignment is screwy in > C, not parameter passing. Sure, if you define "screwy" as "different from Python". But that's the exact problem that got us where we are. >> What would you define LISP's semantics as? Pass by value? Pass by >> reference? Pass by name? Pass by immutability? Pass the salt? > > > Let's see... the expression being passed gets evaluated > once at the point of call, and the result gets bound to > a local name. Looks exactly like pass-by-value to me. Oh, looks exactly like pass-by-name-binding to me, then. Nothing's getting copied, so it can't be pass-by-value. See how non-simple it is? ChrisA -- https://mail.python.org/mailman/listinfo/python-list