[Edu-sig] pyscheme

Seth David Schoen schoen@loyalty.org
Wed, 2 Jan 2002 21:23:08 -0800


My next concern (sorry to non-Scheme folks) is that -- as your BUGS
section explicitly notes -- your "cons" doesn't work with atoms.  Yikes!
Using Python lists to represent Scheme lists is very clever, and saves
lots of memory, but this restriction on cons seems like a big change
to Scheme.

I think I have come up with an elegant solution which allows you to
create pairs which aren't Scheme lists, while retaining the use of
Python lists as the underlying representation of the result of cons
operations which _do_ create Scheme lists (for efficiency).

This is to detect whether the second argument to cons is a list (which
you do), but, instead of raising an error if it's not, represent such
Scheme pairs as Python tuples (of length 2).  This requires trivial
modifications to cons and cdr (and a change to the error-checking
in car), but it appears to have no other effects.  The bonus is that
you automatically get pair output which looks like

(FOO, BAR)

where Scheme would print

(FOO . BAR)

to indicate a non-list pair.  By contrast, the corresponding Scheme
list -- which can be created with (cons 'foo (cons 'bar '())), even
after my proposed modification -- is still displayed, in proper
Scheme style, as

(FOO BAR)

I will send you my updated scheme.py so you can look at this.

-- 
Seth David Schoen <schoen@loyalty.org> | Reading is a right, not a feature!
     http://www.loyalty.org/~schoen/   |                 -- Kathryn Myronuk
     http://vitanuova.loyalty.org/     |