-
-
Save igjit/9261b0459445fa728a16cf65b63d263e to your computer and use it in GitHub Desktop.
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
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