1989lzhh schrieb am 07.11.2014 um 05:48: >> 在 Nov 7, 2014,02:56,Robert Bradshaw 写道: >> Here's some proposed function pointer syntaxes; which are the most >> obvious to understand/read/remember? Can you figure them out? >> >> cdef float (*F)(float) >> cdef float (*G)(float (*)(float), float, float) >> cdef float ((*H)(char*))(float (*)(float), float, float) >> >> vs >> >> cdef float -> float F >> cdef (float -> float, float, float) -> float G >> cdef (char*) -> (float -> float, float, float) -> float H >> >> vs >> >> cdef lambda float: float F >> cdef lambda (lambda float: float), float, float: float G >> cdef lambda (char*): lambda: (lambda float: float), float, float: float H >> >> >> If you want a hint, the last is something that returns numerical >> integration algorithm given a string name. Yes, you could use >> typedefs, but you shouldn't have to. especially for the first. >> > Here are numba kind function annotation, I guess it may fit in here. > cdef float(float) F > cdef float(float(float), float, float) G > cdef float(float(float), float, float)(char*) H > I personally feel this kind of annotation is more packed that using ->.
I find it clearer than any of the above. And it still allows the use of named arguments, i.e. you could say cdef char*(float x, int y) F = ... F(y=1, x=2.0) Drawback is that you have to parse up to the name in order to distinguish it from cdef char*(float x, int y): ... Then there's also cdef char*(float x, int y) nogil F And we have to disallow cdef char*(float x, int y) with gil F It gets a bit less readable when you take a proper lower-case variable name, e.g. cdef char*(float x, int y) nogil get_gil We could fix some of that by allowing cdef nogil: cdef char*(float x, int y) get_gil But then, that's adding yet another special case. Stefan _______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel