Sturla Molden skrev:
> We have the same sematical difference when calling functions:
>
>    void foobar(int& c);
>
> the reference c is intialized to alias the argument with which foobar is 
> called. But you can never rebind c to alias another object in the local 
> scope of foobar. If you assign to c you modify the variable aliased by c.
>   

And as for Python, if we have

   c = 5
   foobar(c)

the value of c cannot be changed as c is immutable.

But if we have

   from ctypes import c_int
   c = c_int(5)
   foobar(c)

then the call to foobar can change the value of c by assigning to 
c.value in its local scope. 

In either case, if foobar assigns to c in its local scope (i.e. rebinds 
the name), nothing happens to c in the calling scope.

This is obviously very different from C++, but in neither case can 
foobar rebind the argument in the calling scope.

We should not confuse the issues of name binding vs. assignment and 
mutability vs. immutability. It's not the same. But Python and C++ 
differs in both cases.

Only in pedantic functional languages are you a guaranteed that 
foobar(x) does not have side effects on x. I am not sure why you are 
worried about side effects on x from a function call foobar(x) in C++. 
Both languages can produce side effects on x here. But C++ does not have 
immutable types.


Sturla





























  

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to