0
votes

I am new to meta programming . I have a module like this

defmodule transport do
  use Qber.Web, :status
  some[some_option]
end

In my web.ex. I have define this status like this:

 def status do
  quote do
    use Qber.Status
  end
 end

This is my status module

 defmodule Qber.Status do
   @moduledoc """

   """
   defmacro __using__(_options) do
     quote do
       code
     end
   end
   defmacro some(options) do
     quote do
       options = unquote options
       IO.inspect options
     end
   end
end

When i use Qber.Web,:status.its working fine but I also want to send the value from some to the macro in the status module right now its giving error some undefined in transport. How can i do this?

1
Can you post the exact error message and if possible an MCVE (stackoverflow.com/help/mcve)?Dogbert
@Dogbert This is the error warning: variable "some" does not exist and is being expanded to "some()", please use parentheses to remove the ambiguity or change the variable name Transport.exs:4 ** (CompileError) Transport.exs:4: undefined function some/0script
Shouldn't it be some(some_options) or are you trying to magically inject the some variable at some point? It is best if you state which problem you are trying to solve, since meta-programming is rarely the answer.José Valim

1 Answers

0
votes

It's hard to tell what you are trying to do exactly without some more context.

However, use doesn't import functions or macros, try adding import:

 defmodule Qber.Status do
   defmacro __using__(_options) do
     quote do
       import Qber.Status
       code
     end
   end

   defmacro some(options) do
     quote do
       options = unquote options
       IO.inspect options
     end
   end
end

Also, it's worth repeating what José said in the comments:

It is best if you state which problem you are trying to solve, since meta-programming is rarely the answer.