Hello,
I’m looking for some hidden Elixir -> Erlang syntax sugar that would improve/simplify my code like:
defmodule X do; def f(a \\ 4, b), do: a + b; end
that is docompiled into:
-compile(no_auto_import).
-file("x.ex", 1).
-module('Elixir.X').
-export(['__info__'/1, f/1, f/2]).
-spec '__info__'(attributes | compile | exports |
functions | macros | md5 | module |
native_addresses) -> atom() |
[{atom(), any()} |
{atom(), byte(), integer()}].
'__info__'(functions) -> [{f, 1}, {f, 2}];
'__info__'(macros) -> [];
'__info__'(info) ->
erlang:get_module_info('Elixir.X', info).
f(x0@1) -> f(4, x0@1).
f(a@1, b@1) -> a@1 + b@1.
which I can use nicely with Ecto to get scoped queries e.g.
def get_users(admin) do
admin |> visible() |> Repo.all()
end
defp visible(query \\ User, %Admin{client_id: client_id, permissions: permissions}) do
if "super_admin" in permissions do
query
else
query |> where([u], u.client_id == ^client_id)
end
end
or (&(&1 + &2))
is replaced by &:erlang.+/2
with I recently found to translate:
parse(["+"|Xs],Expression) -> parse(Xs,[fun erlang:'+'/2|Expression]);
into
defp parse(["+" | tail], exp), do: parse(tail, [(&(&1 + &2)) | exp])