Last active
January 9, 2018 14:56
-
-
Save Yoxem/f78ad39c13023bbf63bbf6bf236e5101 to your computer and use it in GitHub Desktop.
A lisp-like list "interpreter"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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