I want to query an ETS table based on a condition. As per Erlang’s doc, I should be able to use variables in scope.
Is it possible to formulate the query below with this “imported variable” in Elixir ?
def get(id) do
fun = :ets.fun2ms(fn {x,y,z,:_} when x == id or y == id -> {x,y,z} end)
:ets.select(:table, fun)
end
This does not work with a variable, but works with a value.
(FunctionClauseError) no function clause matching in :ms_transform.normalise/1
You can obtain the result as below but not satisfied
fun2ms and friends are parse transformations, they can be used from the shell, but the transformation is applied at compile time using ms_transform.hrl which cannot really be done in elixir. See the full documentation especially the warnings at the end of the documentation.