Rich_Morin
This question is a bit convoluted, so please bear with me…
I have some common functions that I use occasionally for tracing and such. For example, Common.ii/2 provides a shorthand version of IO.inspect/2:
foo = bar
|> ii(:bar)
...
If I want to keep a trace around for later, I comment it out. To keep my code tidy, I use an import statement:
import Common, only: [ ii: 2 ]
However, if none of the traces are currently in use, this generates a warning:
warning: unused import Common
So, I have to comment out the import line:
# import Common, only: [ ii: 2 ]
My problem arises when I import more than one function, only one of which may need to be commented out:
import Common, only: [ ii: 2, str_list: 1 ]
I tried using multiple import statements, but this fails silently (only the last one takes effect):
import Common, only: [ ii: 2 ]
import Common, only: [ str_list: 1 ]
So, I’m forced to use some rather awkward code formatting:
import Common, only: [ # ii: 2,
str_list: 1 ]
Comments? Clues? Suggestions?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
usethe module and return a quoted expression that isgenerated: true.Rich_Morin
Thanks for the prompt response. However, after Googling a bit and trying things out, I don’t think this will work for my use case.
Problem is, my
Commonmodule (following @PragDave’s suggested approach) only containsdefdelegatestatements. So, when I wrap my tracing functions (inCommon.Tracing) in the quote, Elixir gets very annoyed.More generally, this approach seems a bit arcane, given the (seemingly) simple thing I’m trying to accomplish. Is there some fundamental reason why multiple
importstatements can’t be used for the same module?NobbZ
I do not understand what you consider arcane there?
PS: I do not know much about @pragdaves approach, except that I don’t use it, and also I’m not sure if I like the additional reductions it does cost.
Rich_Morin
I tried playing with this a bit and it caused my compile to blow up. This seems like a rathole, so I think I’ll punt for the moment…
NobbZ
Yes, sorry, typed that on my mobile. This works for me:
Rich_Morin
Thanks; that works nicely. I (carefully!) modified my code base to use it and it passes both dialyzer and my tests.
I doubt whether the added reductions have any significant impact, unless a function is being called in the middle of a tight loop. Given that these functions are part of a library or component, this isn’t all that likely.
FWIW, I’m very happy with PragDave’s approach. It lets me organize my implementation code into a hidden set of small, cohesive modules. It also lets me write public (and thus testable and documentable) functions that aren’t part of the “official” API.
LostKobrakai
You can also disable warnings on the callers side:
Rich_Morin
Cool! I like this better than the
useapproach, for multiple reasons:importfor all of my libraries.Thanks.