def file_to_string(filename):
    f = open(filename + ".py")
    return f.read()

sloop = file_to_string("loop")

sloop

print sloop

exec(sloop)

loop(1)

loop(2)

smystery = file_to_string("mystery")

print smystery

exec(smystery)

mystery(42)

sself_apply = file_to_string("self_apply")

print sself_apply

exec(sself_apply)

def ident(x):
    return x

ident(1)

ident(ident)

ident(ident)(1)

self_apply(ident)

self_apply(ident)(1)

self_apply(self_apply)

sdetect_trivial_loop = file_to_string("detect_trivial_loop")

print sdetect_trivial_loop

exec(sdetect_trivial_loop)

halt_test(sloop, 1)

halt_test(smystery, 42)

halt_test(sself_apply, sself_apply)

self_apply(sself_apply)

halt_test(sself_apply, self_apply)

sfool_detect_trivial_loop = file_to_string("fool_detect_trivial_loop")

print sfool_detect_trivial_loop

halt_test(sfool_detect_trivial_loop, sfool_detect_trivial_loop)

exec(sfool_detect_trivial_loop)

fool_detect_trivial_loop(sfool_detect_trivial_loop)

smake_fooler = file_to_string("make_fooler")

print smake_fooler

exec(smake_fooler)

sfool_halt_test = make_fooler(sdetect_trivial_loop)

print sfool_halt_test

halt_test(sfool_halt_test, sfool_halt_test)

exec(sfool_halt_test)

fool_halt_test(sfool_halt_test)

sdetect_self_application = file_to_string("detect_self_application")

print sdetect_self_application

exec(sdetect_self_application)

halt_test(sloop, 1)

halt_test(sself_apply, sself_apply)

halt_test(sself_apply, self_apply)

sfool_halt_test = make_fooler(sdetect_self_application)

print sfool_halt_test

halt_test(sfool_halt_test, sfool_halt_test)

exec(sfool_halt_test)

fool_halt_test(sfool_halt_test)

