You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when selecting with a tuple in the guards, one gets a "badarg" error. Generally speaking, the error message is not very helpful because it 1) doesn't specify where 2) dumps Erlang match specification which is complex to read.
This of course stems from Erlang trying to interpret the tuple as a match specification, instead of as a literal. However, the specification states that {:const, <original value here>} can be used to mark literals. I.e., a guard in memento syntax like this fails:
{:==,:year,{1993,1994}}
whereas this succeeds (query works, but is non-sensical with the test suite schema):
{:==,:year,{:const,{1993,1994}}}
I did a superficial test with memento's test suite, and updating the spec translator at
to emit {:const, <literal>} instead of simply <literal> makes the first example "just work" without breaking any of the other test cases.
I have no experience with Erlang's match spec, and this almost seems too easy to not have any side effects I'm simply not aware of. And of course, changing it now in Memento is a breaking change.
However, at least mentioning this trick in the select/3 documentation would be appreciated, to avoid having to read up on the match spec docs for slightly more complicated than normal cases.
The text was updated successfully, but these errors were encountered:
breunigs
changed the title
make querying with tuples easier
make selecting with tuples easier
Jan 7, 2025
Currently, when
select
ing with a tuple in the guards, one gets a "badarg" error. Generally speaking, the error message is not very helpful because it 1) doesn't specify where 2) dumps Erlang match specification which is complex to read.This of course stems from Erlang trying to interpret the tuple as a match specification, instead of as a literal. However, the specification states that
{:const, <original value here>}
can be used to mark literals. I.e., a guard in memento syntax like this fails:whereas this succeeds (query works, but is non-sensical with the test suite schema):
I did a superficial test with memento's test suite, and updating the spec translator at
memento/lib/memento/query/spec.ex
Lines 58 to 60 in f06bc68
{:const, <literal>}
instead of simply<literal>
makes the first example "just work" without breaking any of the other test cases.I have no experience with Erlang's match spec, and this almost seems too easy to not have any side effects I'm simply not aware of. And of course, changing it now in Memento is a breaking change.
However, at least mentioning this trick in the
select/3
documentation would be appreciated, to avoid having to read up on the match spec docs for slightly more complicated than normal cases.The text was updated successfully, but these errors were encountered: