[pypy-dev] __builtin__ module

Scott Fenton scott at fenton.baltimore.md.us
Fri Jan 24 13:43:13 CET 2003


On Fri, Jan 24, 2003 at 10:39:35AM +0100, Armin Rigo wrote:

> About chr(i) vs. '%c'%i vs. '\x00\x01...\xFF'[i]:  what I feel this shows is 
> that one of these solutions must be thought as the primitive way to build a 
> character, and the others should use it; and I definitely feel that chr() is 
> the primitive way to build a character.  Contrary to what I said in a previous 
> e-mail I don't think that chr() should be implemented with '%c'%i.  On the 
> other hand, I guess that the strings' % operator could nicely be implemented 
> in pure Python.  It would then have to use chr() to implement the %c format 
> code.  It looks more reasonable than the other way around.
> 

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 (or Java, or a Python compiler, or....). I
guess since builtin types fit below that level, we should probably
make '%c'%i the builtin way of conversion, and, in fact, the new version
of pypy.py I'm putting together has it that way. Another good, compelling
argument is that it would be idiotic to try to implement unichr the 
other way, so for consistency we should probably delegate the task of
character->number to C, where it can be done more gracefully anyway.

-Scott

-- 
char m[9999],*n[99],*r=m,*p=m+5000,**s=n,d,c;main(){for(read(0,r,4000);c=*r;
r++)c-']'||(d>1||(r=*p?*s:(--s,r)),!d||d--),c-'['||d++||(*++s=r),d||(*p+=c==
'+',*p-=c=='-',p+=c=='>',p-=c=='<',c-'.'||write(1,p,1),c-','||read(2,p,1));}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20030124/7746c0db/attachment.pgp>


More information about the Pypy-dev mailing list