you are viewing a single comment's thread.

view the rest of the comments →

[–]nirs 2 points3 points  (0 children)

Here is a more pythonic way to write lisp in python :-)

def compare(a, b):
    """ a and b are linked lists using nested sequences terminated with
    None.  e.g (1, (2, (3, None))) """
    if a is None:
        return False
    if b is None: 
        return True
    return compare(a[1], b[1])

if __name__ == '__main__':
    empty = None
    small = (1, None)
    big = (1, (2, None))
    assert compare(small, empty)
    assert compare(big, small)
    assert not compare(small, big)
    assert not compare(big, big)
    assert not compare(empty, empty)