Skip to content

Instantly share code, notes, and snippets.

@igjit

igjit/elispr.ex Secret

Created November 15, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igjit/9261b0459445fa728a16cf65b63d263e to your computer and use it in GitHub Desktop.
Save igjit/9261b0459445fa728a16cf65b63d263e to your computer and use it in GitHub Desktop.
defmodule Elispr do
def parse(s) do
s |> String.replace("(", " [ ")
|> String.replace(")", " ] ")
|> String.replace(~r/([^\[\]\d\s]\S*)/, ":\\1")
|> String.replace(~r/([^\s\[:]+)/, "\\1,")
|> String.trim
|> String.trim_trailing(",")
|> Code.eval_string
|> elem(0)
end
def translate([:+ | args]) do
{:+, [], args}
end
def eval(s) do
s |> parse |> translate |> Code.eval_quoted |> elem(0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment