Rich_Morin
Enabling access to occasionally used (eg, tracing) functions?
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?
Most Liked
Rich_Morin
Cool! I like this better than the use approach, for multiple reasons:
- It gets rid of a macro in my code base.
- I can use
importfor all of my libraries. - The caller controls the module usage.
- The whole thing seems more explicit.
Thanks.
LostKobrakai
You can also disable warnings on the callers side:
Popular in Questions
Other popular topics
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









