kokolegorille
Hello everyone,
I have some strange error message when using :ets.fun2ms.
I am trying to filter an ets table based on some time.
def get_obsolete_check_in(time) do
fun = :ets.fun2ms(fn {_, %CheckIn{start_time: start_time}} = check_in when start_time > time ->
check_in
end)
:ets.select(:check_ins, fun)
end
Here is the error message.
** (exit) exited in: :ets.fun2ms(:function, :called, :with, :real, :fun, :should, :be, :transformed, :with, :parse_transform, :or, :called, :with, :a, :fun, :generated, :in, :the, :shell)
** (EXIT) :badarg
(stdlib) ets.erl:580: :ets.fun2ms/1
(next_engine) lib/next_engine/check_in_server.ex:30: NextEngine.CheckInServer.get_obsolete_check_in/0
This also happens with a simple function like
fun = :ets.fun2ms(fn check_in -> check_in end)
:ets.select(:check_ins, fun)
Looking for an answer I found similar problems in Erlang here. And it seems the Erlang solution would be to include…
-include_lib("stdlib/include/ms_transform.hrl").
How does this translate to Elixir?
Thanks for taking time.
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hi all!
I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
I have a page in my Phoenix app with some LiveView code. When you click a button, it shows the Stripe credit card modal form via a Hook. ...
New
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
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
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
(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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
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
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #security
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
rvirding
The problem is that the fun must be converted to a match spec at compile time. In Erlang the “ms_transform.hrl” file causes a parse transform to be run which at compile time recognises the call to
:ets.fun2ms/1and converts the fun to a match spec. It basically behaves like a macro. If the function is called at run-time you get the error.How this is handled in Elixir I don’t know.
EDIT: Funnily enough I have just been working fixing the handling of match specs in LFE (Lisp Flavoured Erlang), amongst other things writing and
ets-msanddbg-msmacros which do this conversion.kokolegorille
Thank You for your response.
I tried this simple module, it fails with the same error. But if I type each line in the console, it’s working.
I probably need to translate this line in Elixir, but I don’t know yet how to do it.
rvirding
This is because the shell “knows” about the
:ets.fun2ms/1function and handles it specially, and:dbg.fun2ms/1as well.The
:dbgversion is for match spec for tracing which are a little different, the:etsversion is for return data while th:dbgversion do tracing commands.pmonson711
I’ve always used ex2ms | Hex to achieve this in Elixir.
kokolegorille
That lib seems to be exactly what I need.
Thank You very much.
kokolegorille
I got it working, but it is a bit more complex than previously thought.
for future reference, if You happen to search into an ets table storing Elixir structure by key (here by date). You will need Ex2ms, and use correct syntax.
Here is pseudo code, with 3 functions f, the last one is working.
The first try with :ets.fun2ms works in iex, but fails when defined in a module with error.
The second try with Ex2ms fails with error. You cannot extract start_time directly from the Elixir structure.
The solution is to store start_time in the key, so that Ex2ms can generate a match_spec from a single var, part of the key. Do not forget the little ^ when matching.
Thank You @rvirding and @pmonson711 for your kind help.
rvirding
Yes, while you can put structs in an ETS table you cannot put them directly in the table as the elements in an ETS table must be tuples so the struct itself must one of the elements of the tuple.
sasajuric
For
:ets.fun2msto work, you should add@compile {:parse_transform, :ms_transform}into your module.kokolegorille
Thank You for the response. This will remove the need for ex2ms.
kokolegorille
After getting some warnings with Elixir 1.6 and Erlang 20.1
I found this issue
https://github.com/elixir-lang/elixir/issues/5762
The better way now seems to be using ex2ms, losing some supports for better compilation.