Nazari
Anyone can help me? Why compiler is throwing this error?:
** (ArgumentError) argument error
(stdlib 3.13) :lists.keyfind(:counter, 1, :SyncKey)
(elixir 1.10.4) src/elixir_utils.erl:45: :elixir_utils.var_context/2
(stdlib 3.13) lists.erl:1354: :lists.mapfoldl/3
Here is the source:
defmodule Problem do
def sample,
do: {
:foldercreate,
{:FolderHierarchy, :FolderCreate,
[
{:FolderHierarchy, :SyncKey, :reqres},
{:FolderHierarchy, :ParentId, :req},
{:FolderHierarchy, :DisplayName, :req},
{:FolderHierarchy, :Type, :req},
{:FolderHierarchy, :Status, :res},
{:FolderHierarchy, :ServerId, :res}
]}
}
defmacro res_cmd() do
{fnname, {namespace,container,lista}} = sample()
quote do
def unquote(fnname)(:res, pars) do
{
unquote(namespace),
unquote(container),
unquote(lista)
|> Enum.filter(fn {_, _, ty} -> ty == :res or ty == :reqres end)
|> Enum.map(fn {a,b,_c} -> {a,b,pars[b]} end)
}
end
end
end
end
defmodule Injected do
require Problem
Problem.res_cmd()
end
Trending in Challenges
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nazari
This is getting strange… this version works; it defines a function foldercreate into module Injected as desired:
kip
Macros, like functions, have to be compiled and available before they can be called. Since macros are expanded at compile time, they need to be defined in a separate module and can’t be defined in the same module that calls them. Which is why your second example works. Its actually the same for functions. For example the following would also not work.
LostKobrakai
With defmacrop they can be in the same module, but need to be defined before being used only later in the same module‘s code.
kip
Interesting. TIL …
Although of course logically they have to be executable in the same module as defined, since they are private.
Nazari
Hi kip; the fact is that the definition of the macro is in module Problem, and used in module Injected. The same behavior occurs it you split in two files each for a module. Also, the second version posted works, with no problem. I’ve reported this to elixir-lang, may be a bug (Compile error for function definition via macro · Issue #10308 · elixir-lang/elixir · GitHub)
Thanks for your reply