Last active
June 7, 2016 12:28
-
-
Save duksis/429ebbbf1c83a2a35ecd853505e898f0 to your computer and use it in GitHub Desktop.
unqoting data
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 characters
# helper function for creating double modules | |
# with function `call` returning initially provided data | |
# | |
# argument exampes: | |
# name = SomeModuleTest.ForTestCase | |
# data = [%{"some" => "data"}] | |
def create_double_module(name, data) do | |
contents = quote do | |
def call(_module, _fun, _args) do | |
unquote(data) # Invalid quoted expression (as thats data and not quoted code) | |
end | |
end | |
Module.create(name, contents, Macro.Env.location(__ENV__)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
unquote(Macro.escape(data))
works thanks to @michalmuskala