Life's better without braces

Andrew M. Kuchling akuchlin at mems-exchange.org
Mon Feb 21 17:28:02 EST 2000


"Thomas A. Bryan" <tbryan at python.net> writes:
> Gerrit, this is the strangest thing I've ever seen.  I sure hope that 
> it's just getting late, and you're being silly.  You didn't really 
> rip keys off of your keyboard, did you?

This is probably just a _jeu d'esprit_, done less out of seriousness
than out of curiosity (to see if it's possible to get things done
under that constraint).  Similar games might include changing your
login shell to /usr/bin/emacs [1], reimplementing the Unix command set
in Perl (http://language.perl.com/ppt/), writing code in Intercal, or
trying to write pure Python versions of as many built-in functions as
possible.  [2]

[1] Greg Ward just observed that it's possible to boot Linux and pass
it "init=/usr/bin/emacs", to run Emacs as the single process on the
system.  The return of the Lisp Machine!

[2] I occasionally think about this problem.  The setup: GvR was far
too profligate in adding functions to bltinmodule.c that could have
been written in pure Python instead.  So, how many built-in functions
can you re-implement in pure Python?  (Efficiency, and indeed sanity,
aren't important criteria.)  Examples:

def repr(thing): return `thing`

# Can't use chr() and a loop to make this dictionary...
chrdict = {0:'\000', 1:'\001', ... 255: '\377'}
def chr(i): 
    if not (0<= i < 256): raise ValueError, "chr() arg not in range(256)"
    return chrdict[i]

def hasattr(obj, name):
    s = 'obj.' + name
    try:
        exec s
        return 1
    except AttributeError:
        return 0

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
The concept is staggering.  Pointless, but staggering.
    -- The Doctor, in "The Pirate Planet"





More information about the Python-list mailing list