vrod
Is there a way to put more functions into __using__ block? It gets very long and hard to read. I cannot figure out how to split up the quote do into multiple functions. Is there a trick?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #elixirconf-us
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
@vrod I’ll start by saying: If this is a problem you’re running into, you are 100% putting too much inside of a
__using__block. Code inside of a using block should generally look like this:NOT
Doing it the first way will improve compile times, debugging ability, and avoid the problem you are running into.
BUT, to actually answer your question, you can do this;
Basically, return a list of
quote doblocks.vrod
I see, thank you. In your example, you end up having more public functions available, yes? I think sometimes this might make a problem?
benwilson512
You can
@doc falsethose functions if you want to make it clear that they aren’t supposed to be used.eksperimental
I don’t know if I quiet understand your question, but you can put as many functions as you please inside the quote do block in using.
For instance:
And then
kip
If the only purpose of the
__using__macro is to define functions that have no dependency on macro arguments then I think justimport MyModuleis far clearer in intent and easier to maintain. I can’t tell if your use case fits this description though.Otherwise, as @benwilson512 says, the quoted code should do as little as possible and delegate to normal functions early for the same reasons as clear intent and maintainability.
vrod
I have arguments passing in
use, soimportdoes not work (maybe there is a trick?). My purpose is to simplify many functions: when Iusewith arguments, I can make many functions in a module that are much more simpler. For instance instead ofsomething1(shared1, shared2, x, y),something2(shared1, shared2, x, y), …I can do
use Thing, shared1: "a", shared2: "b"and then have much simpler functions likesomething1(x, y)because the macro put the shared values where they are needed.The quote gets long with
@docespecially, so even if there is no complex logic in the functions and they are simple calls to some other functions like @benwilson512 says, it is helpful to organize things in smaller pieces sometimes. I hope that makes senseeksperimental
I would recommend against that. Be explicit and avoid magic.
Later you will loose understanding of what’ s going on with your code.
benwilson512
Yea I agree with @eksperimental here, this use of macros generally causes more trouble than it’s worth.
If you find yourself with functions that take too many arguments, consider creating a struct and then passing on that struct. For example:
Then you construct a
%SomeModule{}struct and it will take on the relevant defaults, and also provide a place to store other values you want to set. Then you can pass this to your various functions, and add extra arguments as appropriate.