> This is (again) sort of an in-between C and Python question. "cdef" enters C
> space, where block-scoping makes sense. However, we'd have to resolve all
> sorts of weird semantic nonsense, such as:
>
>     cdef object i
>     for i in range(10):
>         cdef long i = i
>         ...
>
> I don't feel like bothering with that...
>   
Hmm. You're right. Even worse:

if mytest:
   cdef float x = 2
else:
   cdef int x = 2
print x

One would either have to use "C-like scope" for typed variables (doesn't 
smell good), or know about execution paths and raise compiler errors on 
the wrong scenarios (don't like that either). If there are some simple 
rules to allow it in a few simple obvious cases it would be good though, 
and just don't allow any possible nonsense. Something like:

syntax error: The variable "x" is used outside of the typed block. Move 
the type declaration.
syntax error: "x" has a type declared more than once within a function.

If one can do this check it should handle most cases, and can be 
implement it simply by moving all the cdefs (splitting cdef and 
assignment if necesarry) to the top of the function during compile.

But perhaps better left for later.

Dag Sverre
_______________________________________________
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to