Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make selecting with tuples easier #41

Open
breunigs opened this issue Jan 7, 2025 · 1 comment
Open

make selecting with tuples easier #41

breunigs opened this issue Jan 7, 2025 · 1 comment

Comments

@breunigs
Copy link

breunigs commented Jan 7, 2025

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

defp translate(_map, term) do
term
end
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.

@breunigs breunigs changed the title make querying with tuples easier make selecting with tuples easier Jan 7, 2025
@fabio-t
Copy link

fabio-t commented Jan 15, 2025

I just hit this kind of issue - thank you for this @breunigs!

A fix in Memento would be really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants