def link(code): code = as_code(code) free = free_vars(code) to_bind = sorted(var for var in free if var[1].startswith('lib.')) for var in to_bind: code = bind(code, var) return code
def test_as_code(arg, expected): actual = as_code(arg) assert actual == expected
def test_link(code, expected): expected = as_code(expected) actual = link(code) assert actual == expected
def bind(code, var): assert var[1].startswith('lib.') name = var[1][4:] defn = getattr(lib, name) # raises AttributeError if not found. return substitute(var, as_code(defn), code)
def test_intro_forms(name, native): assert as_code(getattr(lib, name)) == as_code(native)
def test_fun_type_fixes(value, type_): assert reduce(app(type_, value)) == reduce(as_code(value))
def test_compose(f, g, expected): assert reduce(as_code(compose(f, g))) == simplify(as_code(expected))