[pypy-dev] __builtin__ module
arigo at tunes.org
Wed Jan 22 17:22:43 CET 2003
On Tue, Jan 21, 2003 at 09:05:14PM -0500, Scott Fenton wrote:
> I've hacked up some basic replacements for
> various functions in __builtin__.
Fine! The greatest benefits of your code is that it clearly shows what can be
directly implemented in Python, what could be, and what cannot.
A function like chr() is in the second category: it could be written in Python
as you did, but it is not "how we feel a chr() implementation should be". It
should just build a one-string character, putting 'i' somewhere as an ASCII
code. But how?
This problem, and the deeper problems with some other functions, come from the
fact that you placed your code at the same level as the Python interpreter.
The functions you wrote could be used in the current CPython interpreter, in
place of the existing built-ins. In PyPython, these are functions that we
will populate the emulated built-ins with. We still need two levels: the
functions that operate at the same level as the interpreted programs (like
yours), and the functions that operate at the level of the interpreter (like
CPython's built-in functions). In other words, we still need the notion of
built-in functions that will be as "magic" as CPython's in the sense that they
do something that couldn't be done by user code. You see what I mean when you
try to rewrite the type() builtin :-)
PS: just a comment about abs(), cmp() and len(). These should use the
underlying __abs__(), __cmp__() and __len__() methods, as you have done for
apply(), bool(), hash(), pow() and repr().
More information about the Pypy-dev