Thank you Eric,
all clear now.
For some reason I was thinking that the modules and macros/functions I was 
seeing in functions:  and
macros: were the required modules, but they were the imported ones.

Thanks Michał and OvermindDL1 for clarifying as well.
have a nice day!

 On Thu, 8 Sep 2016 12:05:34 +0200
Eric Meadows-Jönsson <eric.meadows.jons...@gmail.com> wrote:

> Inside a macro the callers environment is available in __CALLER__. The
> imported modules are actually available in the environment as Michal said
> and OvermindDL1 showed:
> 
> iex(1)> __ENV__.macros  
> [{IEx.Helpers,
>   [b: 1, h: 1, import_file: 1, import_file: 2, import_file_if_available: 1,
>    import_if_available: 1, import_if_available: 2, s: 1, t: 1]},
>  {Kernel,
>   [!: 1, &&: 2, ..: 2, <>: 2, @: 1, alias!: 1, and: 2, binding: 0, binding:
> 1,
>    def: 1, def: 2, defdelegate: 2, defexception: 1, defimpl: 2, defimpl: 3,
>    defmacro: 1, defmacro: 2, defmacrop: 1, defmacrop: 2, defmodule: 2,
>    defoverridable: 1, defp: 1, defp: 2, defprotocol: 2, defstruct: 1,
>    destructure: 2, get_and_update_in: 2, if: 2, in: 2, is_nil: 1, match?: 2,
>    or: 2, pop_in: 1, put_in: 2, raise: 1, raise: 2, reraise: 2, reraise: 3,
>    sigil_C: 2, sigil_D: 2, sigil_N: 2, sigil_R: 2, sigil_S: 2, sigil_T: 2,
>    sigil_W: 2, sigil_c: 2, sigil_r: 2, sigil_s: 2, ...]}]
> 
> In the code snippet above you can see the modules IEx.Helpers and Kernel.
> They are imported modules.
> 
> You can also see from where a function/macro was imported in the AST:
> 
> iex(2)> quote(do: is_nil(1))  
> {:is_nil, [context: Elixir, import: Kernel], [1]}
> 
> See the import: Kernel in the snippet above.
> 
> On Thu, Sep 8, 2016 at 2:24 AM, eksperimental <eksperimen...@autistici.org>
> wrote:
> 
> > that's the thing,
> > I don't know what modules had been imported (I'm planning on using this
> > inside a macro, that's why
> > the requirements are that it needs to be available at compile-time).
> > pretty much I need to do what Elixir does to determine what is the module
> > being called, when no
> > module is specified.
> >
> >  On Wed, 7 Sep 2016 16:45:01 -0700 (PDT)
> > OvermindDL1 <overmind...@gmail.com> wrote:
> >  
> > > On Wednesday, September 7, 2016 at 5:34:16 PM UTC-6, eksperimental wrote: 
> > >  
> > > >
> > > > thank you Michał, but __ENV__ holds no information about imported  
> > modules.  
> > > > I will be calling the macros/funtions with no module, so somehow I  
> > need to  
> > > > figure out which Module
> > > > I'm going to be calling the macro/function from
> > > >  
> > >
> > > Uh, you sure it does not hold the information?
> > > ```elixir  
> > > iex> import Ecto.Query
> > > iex> __ENV__.macros[Ecto.Query]  
> > > [distinct: 2, distinct: 3, from: 1, from: 2, group_by: 2, group_by: 3,
> > >  having: 2, having: 3, join: 3, join: 4, join: 5, limit: 2, limit: 3,  
> > lock:  
> > > 2,
> > >  offset: 2, offset: 3, order_by: 2, order_by: 3, preload: 2, preload: 3,
> > >  select: 2, select: 3, update: 2, update: 3, where: 2, where: 3]
> > > ```
> > > You should be able to just iterate through `__ENV__.macros` to find which
> > > module the macro belongs to.  There is also a `__ENV__.functions` for  
> > that  
> > > one too.  Just remember to use the __ENV__ in the environment where you
> > > will be calling it in, not from the callee environment.
> > >  
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "elixir-lang-talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to elixir-lang-talk+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/
> > msgid/elixir-lang-talk/20160908072400.4bc10809.
> > eksperimental%40autistici.org.
> > For more options, visit https://groups.google.com/d/optout.
> >  
> 
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-talk/20160909195034.0586320c.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to