Newbie questions

David Grenier grenieda at hotmail.com
Thu Nov 15 15:35:54 CET 2001


Ok got two problems, we're trying to build a mini-scheme interpreter. But I
still think you people could figure out my problem without even knowing
scheme.

class cons:
   """structure de donnée de base pour les paires Scheme"""
   def __init__(self,carpart,cdrpart):
      self.car = carpart
      self.cdr = cdrpart

   def __str__(self):
      a='(' + str(self.car)
      champ=self.cdr
      while type(champ)=='instance':
          a=a + ' ' + str(champ.car)
          champ=champ.cdr

      a=a + ' ' + str(champ) + ')'
      return a

This builds  a cons, a pair as in scheme, when printing it it should output
something like this:
(1 2 3 1) but it seems (i don't understand why and I think I cheked it) to
ouput it like that (1 (2 (3 1))), note that a liste (made of cons) in scheme
is made like this: cons(1 cons(1,2)) this would create the list (1 1 2).





More information about the Python-list mailing list