Created
February 13, 2014 02:36
-
-
Save blvrd/8968751 to your computer and use it in GitHub Desktop.
lisp
This file contains 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 lisp_eval(function) | |
if function[0] == "#" | |
return true if function[1] == "t" | |
elsif function[0] == "(" | |
if function.split('')[1..-2].all?{|letter| letter != ")"} | |
operation_eval(function) | |
else | |
operation_eval function.split(")").to_s.delete("\"").split("(").last.delete(']') | |
end | |
elsif function[0].to_i | |
return function.to_i | |
end | |
end | |
def operation_eval(function) | |
arr = function.delete("(").delete(")").split(' ') | |
operator = arr.delete_at(0) | |
string = String.new | |
arr.each do |element| | |
string << element + operator | |
end | |
return eval string[0..-2] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment