Last active
September 7, 2016 11:30
-
-
Save milesrout/6eb60cefe53cc5687cdb 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
def lazy_any(*args): | |
for arg in args: | |
if bool(arg()): | |
return True | |
return False | |
def is_self_evaluating_term(obj): | |
return lazy_any( | |
lambda: is_primitive_data(obj), | |
lambda: is_primitive_operative(obj), | |
lambda: is_symbol(obj), | |
lambda: is_ignore(obj)); | |
class NilType: | |
def __iter__(self): | |
raise StopIteration | |
Nil = NilType() | |
def is_nil(obj): | |
return obj is Nil | |
class cons: | |
def __init__(self, left, right): | |
self.left = left | |
self.right = right | |
def __iter__(self): | |
yield self.left | |
yield from self.right | |
def make_list(iter): | |
return functools.reduce(lambda x, y: cons(y, x), reversed(iter), Nil) | |
p = cons(1, cons(2, cons(3, Nil))) | |
for x in p: | |
print(x) | |
q = make_list((1, 2, 3)) | |
for x in q: | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment