(Sorry for top-posting, on phone.)

NOTE that this problem is equally present on function arguments: In Python,

f(x)

doesn't ever change the value of x! While in C++, f could take a reference. I'd 
like Cython to not follow C++ here.

There's been long threads about this in the past. My suggestion was to treat 
references as pointers in Cython (they are, after all, C++ syntax csandy for 
pointers)::

f(&x) # output as f(*(&x)) in C++
vec.at(idx)[0] = 0

I still think this is the lesser of all evils. I suppose a special case should 
be made for operator[] (C++ only has a getitem operator while Python 
distinguish getitem/setitem, so some kind of special rule is needed here 
anyway).

Dag Sverre Seljebotn
-----Original Message-----
From: Stefan Behnel <[email protected]>
Date: Friday, Jul 2, 2010 6:12 pm
Subject: Re: [Cython] More c++ bugs
To: toki doki <[email protected]>
CC: [email protected]: [email protected]

toki doki, 02.07.2010 17:57:
>>> While  " *iter=5 " and " vect.at(0)=5 " ares valid C++ code.
>>
>> ... bug not valid Cython code.
>
>This was supposed to spell "but not valid Python code".
>
>
>>> If this is to be supported at all, it needs
>> at least a different spelling.
>>
> I see what you mean. Although "valid cython code" should be a moving
> target.
>
>Sort of, but rather towards less special syntax and more Python syntax. 
>"vect.at(0)=5" doesn't fit anything in Python and someone who wants to make 
>that part of the language will have a hard time getting through my veto.
>
>
>> "new vector[int]()" used to be invalid cython code too.
>
>Right, and although I don't really like reading it, it only works within 
>Cython code that targets C++ (and not pure Python code), so at least it 
>doesn't hurt Python compatibility.
>
>
>> Furthermore, it might also affect the  operator[] (but I can't test
> that due to bug#2). That would mean that "vect[3]=5" would also be
> refused by cython in spite of being valid cython code.
>
>That is perfectly valid Python syntax, though. Overloading that to refer to 
>the C++ [] operator when used on a C++ object sounds fine to me.
>
>
>> I understand correct handling of c++ references will be difficult to
> solve
>
>Absolutely.
>
>Stefan
>_______________________________________________
>Cython-dev mailing list
>[email protected]
>http://codespeak.net/mailman/listinfo/cython-dev
>

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

Reply via email to