Re: What other languages use the same data model as Python?

On May 4, 5:40 pm, Michael Torrie <torr...@xxxxxxxxx> wrote:

Which is exactly what the code showed.  The first one isn't a mistake.
You just read it wrong.

No, I read "call-by-value" but it does not make a copy. Call-by-value
dictates a deep copy or copy-on-write. Python does neither. Python
pass a handle to the object, not a handle to a copy of the object. If
you want to see call-by-value in practice, take a look at MATLAB,
SciLab or Octave; or consider what C++ copy constructors do in
function calls with value types.

The first one is indeed a mistake. An object has a value. A name binds
to an object, not to a value. If Python did pass-by-value, the string
would be inserted in an object (here: a list) with the same value
(e.g. empty list), it would not modify the same object by which you
called the function.

I think you understand what Python does, but not what call-by-value
would do.

C++ tells you the difference:

// copy constructor is invoked
// x is a copy of the argument's value
// this is call-by-value

void foobar1(Object x);

// no copy is taken
// x is a logical alias of the argument
// this is call-by-reference

void foobar2(Object &x);

// x is a pointer, not an object
// x is a copy of another pointer
// this is similar to Python sematics
// the pointer is passed by value, not the pointee

// in C, this is sometimes called call-by-reference
// as there are no reference types, but it's not

void foobar3(Object *x);



Relevant Pages

  • Re: Passing a memory address (pointer) to an extension?
    ... Specifically, when calling PyArg_ParseTuple, what letter should I use to represent the pointer in the format string? ... The best idea I can come up with is to use a long and then cast it to a void *, but assuming that a long is big enough to store a void * is a shaky assumption. ... Just use NULL and let shmat() pick a starting address. ... Using values other than NULL might be unwise but isn't one of the core design philosophies of Python "we're all consenting adults"? ...
  • Re: What other languages use the same data model as Python?
    ... but that's not what takes place at the level of Python ... In Pascal a pointer is a distinct data type, ... to sticking a reference in box a that points to obj. ... So how do you model cycles, including lists that contain ...
  • Re: ctypes.c_void_p(-1) might not be C return (void *) -1
    ... I see the main point leads: "The truth value of any NULL ctypes pointer ... How should I test for ((void *) -1)? ... With Python 2.5 on Windows, I get the same as you. ...
  • Re: Help with PAM and ctypes
    ... addr is the memory address as a Python integer. ... the preferred way to create a NULL pointer in ctypes is to call the pointer type without an argument: ... My initial attempt to fix this involved wrapping strdup to allocate a ... copy of a string to send back to PAM. ...
  • Re: allow line break at operators
    ... people who like Python a great deal and acknowledge, ... I'd go so far as to say that any Python programmer for ... Lemme give a concrete example, from C, since that's the language I know best. ... Pointer manipulation leads to crashes. ...