Skip to content

Instantly share code, notes, and snippets.

@duksis
Last active June 7, 2016 12:28
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 duksis/429ebbbf1c83a2a35ecd853505e898f0 to your computer and use it in GitHub Desktop.
Save duksis/429ebbbf1c83a2a35ecd853505e898f0 to your computer and use it in GitHub Desktop.
unqoting data
# 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
@duksis
Copy link
Author

duksis commented Jun 7, 2016

the goal is to put the value of data in line #11
I tried var!(data), but with that I don't know how to feed the binding in Module.create/3

@duksis
Copy link
Author

duksis commented Jun 7, 2016

unquote(Macro.escape(data)) works thanks to @michalmuskala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment