OrontaMedu

OrontaMedu

Getting a list of modules within a macro -- returns :undefined

Similar to Question on :application.get_key(:my_app, :module)


Why will the 1st call return :undefined, whereas the 2nd will do a list of modules?

defmodule App123.ModLoad do
  defmacro __using__(opts) do
    quote bind_quoted: [opts: opts] do

      var1 = :application.get_key(:app123)
      IO.puts("****:application.get_key: #{Kernel.inspect(var1)}")
      # :undefined
      # why?


      var2 = :code.all_loaded()
      IO.puts("****:code.all_loaded: #{Kernel.inspect(var2)}")
      # a list of modules
      # ...
      # ............

What I need is a list of modules obtained within a macro, and which I’ll then work on with:

  var3 = :application.get_key(:app123, :modules)
  # some work with var3
  # filter out some of them
  # then --> generate a module attribute

However, even var1 is :undefined

Why? And how to fix this?


Namely, the desired result will be that I’ll call use App123.ModLoad in other module(s) – App123.Module2 – which then will generate a certain module attribute – @my_modules – with a list of certain modules I need. At the compile time..

defmodule App123.Module2 do
    use App123.ModLoad
    

    def func1 do
      # now I'll have access to @my_modules 
      # which contains the modules I need
    end
end

Most Liked

dimitarvp

dimitarvp

Sorry that nobody responded yet.

As a general advice, try and make a small public project on GitHub that demonstrates the issue. In my observations people will be more willing to engage then.

Where Next?

Popular in Questions Top

sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement