Dag Sverre Seljebotn wrote:
> Before the C++ syntax sticks

I actually think it makes sense. In declarations, the parameter can appear
only behind type names, so parsing them would be trivial - except for
cases where the type name appears in an expression:

    isinstance(x, MyType<int>)
    type_ref = MyType<int>  vs.  type_ref = SomeValue < something > 5

Not sure if

    type_ref = MyType[int]

makes this any simpler - it may at least simplify the parser, although
there might be further ambiguities with buffers, array sizes and indexing.

I also considered keyword arguments to the type (like Py3's "metaclass"),
but didn't find an obvious way to keep that information in the type name
when referring to it later on.

    cdef class MyType(SomeParent, templates=[T,V]):
        ...

    cdef MyType(T=int, V=list) my_instance
    my_instance = MyType(1,2,3,4, T=int, V=list)

... does that look readable?


> I'd like highlight some benefits of the [] syntax:
>
> - It is legal Python to do "vector[cython.int]()". (Which leaves the way
> open for providing a meta-class doing run-time type-checking of arguments
> and return values, which would be the Python run-time compatability layer
> in the shadow module. That's far off and perhaps too little useful, but I
> like leaving the way open.).

IMHO not a major goal, though. Plus, the type definition itself would
still not match Python's syntax in that case, so the gain is rather
marginal.


> - Guido once used the [] syntax for something similar (which never became
> anything) [1]
> [1] http://www.artima.com/weblogs/viewpost.jsp?thread=86641

Yes, although I wouldn't count on that. If you read the link at the top of
that post (i.e. what became of it), you'll see that that syntax is
basically gone before being examined.


> - Using < and > makes the parser more complicated, while [] must already
> be parsed. (in C++ there's the mess of having to write "vector<vector<int>
>>", note the space, because there would be some problem with the >>
> operator and the parser otherwise).

That's sick. Looks like a scanner problem, though, not a parser problem.
The parser would know that '>>' doesn't make any sense at all at that
position (ok, it's C++, but let's assume a sane kind of 'sense' here).

Stefan

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

Reply via email to