Skip to content

Instantly share code, notes, and snippets.

@Yoxem
Last active January 9, 2018 14:56
Show Gist options
  • Save Yoxem/f78ad39c13023bbf63bbf6bf236e5101 to your computer and use it in GitHub Desktop.
Save Yoxem/f78ad39c13023bbf63bbf6bf236e5101 to your computer and use it in GitHub Desktop.
A lisp-like list "interpreter"
def add(a,b):
return a + b
def exe(x):
if type(x) in [int, float, bool]:
return x
elif x[0] == "if_":
if exe(x[1]) == True:
return exe(x[2])
else:
return exe(x[3])
else:
f = eval(x[0])
input = [exe(y) for y in x[1:]]
return f(*input)
array = ["if_",False,["print",["add", 2, 2]],["print",5]]
exe(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment