Danilo Freitas wrote:
> Dag wrote:
>> from cython import inc, dec
>>
>> Other "magic" functions are already like in the cython namespace (it's
>> not a real module).
>>
>> Note that for STL iterators we also need *it rather than [0], so add
>> "deref" to that list. Or possibly we just add * to Cython?
>>
>> We could then also move on to define the next builtin for C++ classes,
>> which would translate like this:
>>
>> obj = next(it)
>>
>> would become
>>
>> cython.inc(it)
>> obj = cython.deref(it)
> 
> As I said before, I prefer a Pythonic syntax for Cython.
> So, deref() would be better in this case.
> But, for all this and more, we need to define a default syntax.
> Mixing syntax is a little weird and harder to use.
> 
> If we translate C++ syntax to Pythonic  syntax, I think it will be
> easier to use it.
> 
> So, if we gonna do it, many other functions will be added to the list.
> I have some Ideas. Don't know if they are good. But it sounds like:
> 
> my_list = clist(int) #just an example
> it = cython.get_begin_iterator(my_list)
> while it != cython.get_end_iterator(my_list):
>     if something == cython.deref(it): #just a normal if
>         break
>     cython.inc(it)
> 
> So, we could get iterator fom many ways. Just like in STL.

To me, this looks like the main problem is mapping one protocol (in C++) to
another (in Python). Would it help to define some kind of DSL that allows
us to do that? Say, you could define a mapping from (P|C)ython's iterator
protocol (__iter__ and __next__) to corresponding operations in C++, and
Cython would then just insert the corresponding code into the source at the
right places (and maybe replace some place holders). Then you'd have some
default implementation that works with the 'normal' way C++ iterators are
used, and users could extend that to adapt it to other stuff.

I have no idea how such a DSL would look like, so it's really just an idea
(and it's somewhat close to Dag's string insertions). I'm mainly saying
that not everything needs to be implemented by users in Cython code.

Stefan

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

Reply via email to