I've been brewing on this one for a while, with Stefan's other proposal
the time seems about right.

Current situation:
- There is only one namespace "domain"
- However there is an early-bound (compiletime) scope and a late-bound
(runtime) scope.

Things living only in the early-bound scope:
- builtin types, ctypedefs, "cimport .. as x" to some extent

In both:
- cdef classes, cdef functions

In run-time only:
- module attributes/variables, normal classes and functions, "import ... 
as x"

For each kind of type, one has to a certain degree learn and care about 
where they live. I think this should be simplified wherever possible. 
The alternative I see is:

   Everything is run-time symbols, but some symbols are declared
   early-bound and non-overwriteable, and for those optimizations can
   be made.

Another thing I'd like to propose is to shift from thinking about scopes
as such, and instead focus to the time of binding and whether symbols 
can be reassigned at run-time. This is more a mode of thinking than a 
specific proposal, and many proposals could come out of it. Below is a 
few examples (though I should stress that I'm much more interested in 
the general high-level statement above than these -- they are just 
scetches, and they should be CEPed (and one should have time to 
implement them) before any more concrete specific discussion takes place 
for the below):

1) Guarding against overwriting early bound symbols:

$ python
Py> import cymod
Py> import numpy
Py> numpy.ndarray = 4
Py> ^D
WARNING: The symbol "numpy.ndarray" was early-bound by the Cython module
"cymod" but reassigned at run-time.
$

2) A new decorator, say @cython.earlybind, which makes a promise that
the symbol the function/class is stored in isn't reassigned at run-time.
This would extract one aspect of "cdef" functions and modules and make
it orthogonal (and the result would be something like "cpdef module funcs").

The focus could then be on "what Cython can make assumptions about",
rather than having cdef functions as an entirely different class of
functions from def functions.

3) Make run-time objects introspection available for builtin types and 
typedefs, so that you can do "print type(my_typedef)". (But this has 
been touched upon before).

4) By a strong focus on "early-bound symbols" and making
@cython.earlybind a regular construct, syntax like below for typing 
local variables gets a less fragile feel to it:

def f():
     x = cython.int(somefunc()) # means cdef int x = somefunc()

5) Make cdef external functions immedeatily available as Python functions:

mymod.pyx:

cdef extern from "mylib.h":
     int foo(int x)

# foo = 4 wouldn't work: "Cannot assign to early-bound symbol"

def something(x):
   # foo is early-bound so the below is as efficient as today
   return foo(x*4)


Py> import mymod
Py> print mymod.foo(4) # foo is also available at run-time though

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

Reply via email to