I start with a disclaimer I should have made several posts back: I  
have done very little programming with C++, so please excuse any  
naiveté I have in this regard...

On Apr 25, 2009, at 9:54 AM, Dag Sverre Seljebotn wrote:

> Robert Bradshaw wrote:
>> On Apr 25, 2009, at 2:59 AM, Dag Sverre Seljebotn wrote:
>>
>>> Robert Bradshaw wrote:
>>>>
>>>> Perhaps I'm taking a too simplistic view of things, but it seems  
>>>> that
>>>> all we have to do is figure out whether or not we can pass a given
>>>> operator onto the C++ code, which is much easier to reason about.
>>>> Also, because in Python assignment is not an expression, we don't
>>>> have to worry about its return value.
>>>
>>> Hmm. That's a nice perspective to have; but I don't think it is
>>> "obvious" and leads to some fairly concrete consequences IMO:
>>> Operators
>>> must be declared using the Python operator syntax.
>>
>> I'm not so sure about this, I think using declaring the C++ operatorX
>> notation may be more transparent to what is actually going on,
>> despite a (minor) complication in the parser.
>
> I think maintaining a hybrid solution using C++ syntax but different
> semantics (i.e. Cython semantic) is bound to give lots of  
> confusion. I'd
> have no idea what a natural syntax would be personally; we would  
> invent
> something new which just looked like C++.
>
> How would you represent my latter example in my previous mail at  
> using C++
> syntax in Cython?

I would expose your ItemAccessor class as well as your MyCollection  
class in the Cython declaration. This may necessitate exposing the  
notion of a C++ reference to Cython as well. At the very least, I  
think trying to overload on the return type is bad.

>>> So you are never
>>> declaring anything about "operator[]" in Cython, instead you are
>>> declaring "what types are allowed for the full statement 'x[i] =  
>>> y'".
>>
>> Yes, I think that's as far as we need to go.
>
> This is what I think conflicts with letting the operator[] notation  
> into
> Cython. operator[] means nothing of the sort of what we are really
> supporting.

Hmm... OK, maybe I'll take back that statement and say Cython does  
need to go deeper than this. Right now one has to learn the "magic"  
of giving Cython declarations to generate the right code, which is  
undesirable. I would rather not make users have to learn a new  
"magic" but really state what's going on on the C++ side.

The only two non-simple lvalues we need to worry about are indexing  
and attribute access, right?

> C++ is a very complicated language and it's semantics differ a lot  
> from
> Cython. Which is why I'm afraid that using C++ syntax in Cython  
> will be
> confusing.

Unless we give them actual C++ semantics.

- Robert

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

Reply via email to