Last active
September 10, 2019 07:06
-
-
Save archan937/ce525b59a87b3332c8d69a1ddb1a22c2 to your computer and use it in GitHub Desktop.
Revisions
-
archan937 revised this gist
Sep 10, 2019 . No changes.There are no files selected for viewing
-
archan937 renamed this gist
Mar 1, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
archan937 revised this gist
Feb 28, 2019 . 3 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes. -
archan937 revised this gist
Feb 28, 2019 . 3 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes. -
archan937 revised this gist
Feb 28, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # iex(1)> # [ Paste AST module ] # iex(2)> # Generate AST module for the module `Paul.Engel` -
archan937 revised this gist
Feb 28, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ ast |> Macro.to_string() |> IO.puts() # iex(4)> # Compile the generated AST [{mod, binary}] = Code.compile_quoted(ast) # iex(5)> # Ask Paul.Engel to say hi ;) -
archan937 revised this gist
Feb 28, 2019 . No changes.There are no files selected for viewing
-
archan937 created this gist
Feb 28, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ defmodule AST do def compile(module) do module |> generate() |> Code.compile_quoted() end def generate(module) do quote do defmodule unquote(module) do def say_hi(name) do IO.puts("Hi, " <> name) end end end end end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ # iex(1)> # [ Paste AST ] # iex(2)> # Generate AST module for the module `Paul.Engel` ast = AST.generate(Paul.Engel) # iex(3)> # Print the generated AST to Elixir code ast |> Macro.to_string() |> IO.puts() # iex(4)> # Compile the generated AST [{mod, bytecode}] = Code.compile_quoted(ast) # iex(5)> # Ask Paul.Engel to say hi ;) Paul.Engel.say_hi("stranger") 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ # iex(1)> ast = quote do: 1 + 1 # iex(2)> Code.eval_quoted(ast) # iex(3)> ast = quote do: sum(1, 2 + 3) # iex(4)> ast = quote do: fn(a, b) -> a * b end # iex(5)> {func, []} = Code.eval_quoted(ast) # iex(6)> func.(2, 4)