Skip to content

Instantly share code, notes, and snippets.

@milesrout
Last active September 7, 2016 11:30
Show Gist options
  • Save milesrout/6eb60cefe53cc5687cdb to your computer and use it in GitHub Desktop.
Save milesrout/6eb60cefe53cc5687cdb to your computer and use it in GitHub Desktop.
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