Created
August 1, 2015 23:03
-
-
Save dheaney/c28b6fe9d2caa5adb911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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