[erlang-questions] Must and May convention

Joe Armstrong <>
Thu Sep 28 22:07:06 CEST 2017


On Thu, Sep 28, 2017 at 9:11 PM, Michał Muskała <> wrote:
> On 28 Sep 2017, 21:04 +0200, Vans S <>, wrote:
>
>
> I really like the ideas behind this but working with the yrl seems to be an
> undocumented dark art, and very time consuming to
> learn.

yecc is an erlang implementation of an LALR(1) parser. .yrl files
are pretty much like YACC files

In the 'old days computer science student learn LEX and YACC from the
"Dragon book"
https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

The Erlang documentation is sparse since there is copious
documentation of YECC and LEX.

yecc and leex are more-or-less faithful copies of YACC and LEX - the only
difference is the productions are in Erlang not C.

To learn yecc and leex a good way is to find a YACC and LEX grammar
on the net and convert it to Erlang.

Have fun

/Joe


> There is so many things I would like to be able to do and to have
> the code compile to the same/functionally similar abstract form.
>
> my_fun(atom, Map=#{bitfield_set=> _}) ->
>         Value = maps:get(key, Map),
>         Value2 = maps:get(key2, Map, undefined),
>         Value3 = maps:get(key4, maps:get(key3, Map, #{}), undefined),
>         List = io:format("the atom as a binary is ~p ~p", [atom, Value]),
>         unicode:characters_to_binary(List).
>
>     VS
>
> fun my_fun(atom, Map=#{bitfield_set}) ->
>     Value = Map[key]
>     Value2 = Map[key2, undefined]
>     Value3 = Map[key3][key4]
>     "the atom as a binary is #{atom} #{Value}"
> end
>
>
>
> The initial map proposal included a syntax for key access:
>
>     Map#{Key}
>
> But it was never actually implemented.
>
> Michał.


More information about the erlang-questions mailing list