Skip to content

Instantly share code, notes, and snippets.

@dheaney
Created August 1, 2015 23:03
Show Gist options
  • Select an option

  • Save dheaney/c28b6fe9d2caa5adb911 to your computer and use it in GitHub Desktop.

Select an option

Save dheaney/c28b6fe9d2caa5adb911 to your computer and use it in GitHub Desktop.
class Cons():
def __init__(self, car, cdr):
self.car = car
self.cdr = cdr
def __repr__(self):
return "( " + repr(self.car) + ", " + repr(self.cdr) + " )"
def to_list(self):
l = []
l.append(self.car)
if type(self.cdr) == type(self):
for i in self.cdr.to_list():
l.append(i)
elif type(self.cdr) == type(None):
pass
else:
l.append(self.cdr)
return l
def new_cons_list(*args):
if len(args) == 0: return None
return Cons(args[0], new_cons_list(*args[1:]))
l = new_cons_list(1, 2, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment