[erlang-questions] Elixir community, please be more responsible; Erlang community, please demand it.

Fred Hebert mononcqc@REDACTED
Sun Mar 24 20:10:26 CET 2019


On 03/24, Joe Armstrong wrote:
>
>Interesting - I'd imagined that after compilation you'd just end up
>with beam code files after which you could call them from Erlang ...
>
>Could this be rectified by a "better" macro processor for erlang - more
>in the style of the Elixir macro processor ???
>

That could be a thing, but currently Erlang's parse transforms do not 
allow anyone to add any new syntactic element. You can essentially only 
overload and change the meaning of existing Erlang: you can decide that 
`case ... of ... end` changes meaning, but you can't add `custom ...  
end` or anything of that kind.

So if you look at an ecto query such as:

def with_minimum(age, height_ft) do
  from u in "users",
    where: u.age > ^age and u.height > ^(height_ft * 3.28),
    select: u.name
end

You could write an Erlang version that does this through list 
comprehension:

with_minimum(Age, HeightFt) ->
    query([U || U#{age := UAge, height := Height <- "users",
                UAge > Age, Height > HeightFt*3.23])

(which is essentially what QLC does http://erlang.org/doc/man/qlc.html)
Or one using functions:

with_minimum(Age, HeightFt) ->
    from(U, "users",
         where(Maps:get(age, U) > Age,
               maps:get(height, U) > HeightFt * 3.28),
         select(U, name)).

and just overloading the hell of whatever functions mean. But you can't 
introduce any new syntax.




More information about the erlang-questions mailing list