On Mon, Jul 5, 2010 at 12:33 AM, Dag Sverre Seljebotn <[email protected]> wrote: > Sturla Molden wrote: >> 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. >>> > Sorry, this could have been worded better -- references here refers to > Python references = C pointers (more or less), not C++ references. > >> 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. >> > Yes, it was you who brought mutability into the mix; I claimed it was > irrelevant. > > Anyway...you keep stating things that we all know very well. Are you > agreeing or disagreeing with my and Stefan's position? Is there a point > to this discussion at all? > > Specifically: > > cdef int x = ... > cdef MyCppClass *y = ... > f(x, y) > > Do you want f to be allowed, if the arguments are declared as > references, to change the value of x and which memory location y points to? > > There's no need to go into explaining what C++ does (I'm well aware of > it), it's a simple yes or no question, and the question is simply "do we > allow this feature of C++ into the Cython language, or do we take > another approach instead that looks less strange with Python semantics?". > > (Anyway, I think the question is pretty much settled.)
The primary goal with C++ support is to provide just enough C++isms to easily use any of the many C++ libraries out there, but not so much that the user can easily hang themselves. The goal is not to facilitate writing C++ in Cython, but rather using C++ from Cython (though the two overlap quite a bit on the technical plane). If we want to disallow, say, references in function arguments, now is the time to do so. Is there any reason this is necessary to allow? As for the messiness of the rest of C++, we use the new operator because stack allocated objects are a mess (what with mixing scopes and all). Eventually we should be able to catch C++ exceptions with the try/except block, and not let C++ exceptions escape from try/finally which would make things a bit safer. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
