[pypy-dev] __builtin__ module
Armin Rigo
arigo at tunes.org
Fri Jan 24 17:10:08 CET 2003
Hello Scott,
On Fri, Jan 24, 2003 at 07:43:13AM -0500, Scott Fenton wrote:
> I disagree. My feeling about this is probably that everything that can
> be expressed as a function should be in pure python, and that which
> can't should probably be C
No! I was not saying it should be in C. *Nothing* should be in C. I'm using
the word "built-in" to mean a function at the interpreter-level, as opposed to
a function at the application-level.
I still think that the complexity of "string modulo" is best written as a
(non-built-in) Python function.
A thing like chr() on the other hand is trivial to implement as a built-in,
with code like this:
def builtin_chr(v): # v is a PyInt class instance
i = v.parse_long()
if i not in range(256):
raise EPython(PyExc(ValueError),
PyStr('chr() arg not in range(256)')
return PyStr(chr(i))
Compare this with bltinmodule.c:chr().
Yes, I know there is still a call to 'chr()' in my implementation. But I'm at
the interpreter level. The above function (including its chr() call) is easy
to translate to C to make the equivalent of bltinmodule.c:chr().
BTW the syntax "i not in range(256)" is more conceptual than "i<0 or i>=256"
and expresses better what we are testing for (as the error message suggests
too). The above code is a typical example of how I see "built-in" functions
could be written. The function is "built-in" not because it is written in
another language but because it works at the interpreter level.
A bientôt,
Armin.
More information about the Pypy-dev
mailing list