apoorv-2204
I have a module utils,which is supposed to be used by MOdule A, B,C,D… and so on. The issue is utils modules have lot of constants, constants specific to module A,B,C,D … . When i call module utils functions from module A, I want those functions to use constants defined in module A. same for B,C,D,… .What to use Import, use,etc.
So I can call module utils functions, so those util module functions can load constants depending upon which module has made the call.Opposed to passing as variable to the utils module functions. (since there is lot of functions).
So how to determine which module has invoked a function in another module at runtime. So I can leverage that information.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
There is discussion about this here.
I can’t quite visualize what you’re trying to do without seeing code, but if you have code like this:
I would advice against that since it results in
Bbeing a compile time dependency ofA. If you have a lot of stuff like this, compilation can start to get really slow if you aren’t careful about your dependency graph. Otherwise—carry on.apoorv-2204
It can be resolved by passing this extra variable from module, but issue is the function which use this constants are deeply nested, will require to add parameters to all already existing funcs
sodapopcan
I can’t quite picture the nesting but it seems like you might be trying to re-create inheritance here?? There are likely better ways to do what you want to do though not sure how to advise. Hopefully you figured it out via that other topic!
benstepp
It’s possible to do something similar with macros, but fair warning the general rule for macros is not to use them.
al2o3cr
I’m not going to even speculate along this line, because you shouldn’t do this.
Let’s talk about the underlying requirement instead.
Can you be more specific about what you mean by “having constants”? Modules don’t really “contain” anything - for instance, there’s no function in
Moduleto get[Foo.Bar, Foo.Baz, Foo.Wat]given justFoo.A common pattern for this is two parts:
usemacro that creates functions that include this extra argument in a user-controlled namespaceAn example of this is
Ecto.Repo.insert:https://github.com/elixir-ecto/ecto/blob/f6ddc64fbb19588375137f70eea40bfaabf93804/lib/ecto/repo.ex#L304-L313
The underlying function is
Ecto.Repo.Schema.insert, which accepts the repo as a first argument. In a default configuration with nobody callingput_dynamic_repo, that argument will be the module that saiduse Ecto.Repo.In your case, you’d have a module in
Utilsthat defines the__using__macro and then use it in each of A, B, C, D like: