Skip to content

Instantly share code, notes, and snippets.

@blvrd
Created February 13, 2014 02:36
Show Gist options
  • Save blvrd/8968751 to your computer and use it in GitHub Desktop.
Save blvrd/8968751 to your computer and use it in GitHub Desktop.
lisp
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