[erlang-questions] [ANN] Erlson - dynamic name-value dictionary data type and syntax

Anton Lavrik alavrik@REDACTED
Mon Aug 29 06:50:22 CEST 2011


Hi list,

It is my pleasure to announce Erlson - a proof of concept
implementation of dynamic dictionary data type. It can be best
described by examples:

    X = #{},  % create an empty dictionary

    D = #{foo = 1, bar = "abc", fum},  % associate fields 'foo' with
1, 'bar' with "abc" and 'fum' with 'true'

    1 = D.foo,  % access dictionary element

    D1 = D#{baz = #{fum = #{i = 0}}},    % add nested dictionaries to
dictionary D

    0 = D1.baz.fum.i,     % access elements of the nested dictionary

    D2 = D1#{baz.fum.i = 100, baz.fum.j = "new nested value"}. %
modify elements of the nested dictionary
    ...

    erlson:to_json(D2).   % convert Erlson dictionary to JSON iolist()

    D = erlson:from_json(Json).  % create Erlson dictionary from JSON iolist()
    ...

    D = erlson:from_proplist(L).     % create Erlson dictionary from a proplist

    D = erlson:from_nested_proplist(L).  % create nested Erlson
dictionary from a nested proplist


Erlson implementation is fully working and includes syntax support,
runtime library and rebar packaging. The source code is available on
GitHub: https://github.com/alavrik/erlson

Internally, Erlson dictionaries are represented as orddicts, i.e.
ordered lists of {atom(), any()} pairs. This way, they can be easily
printed, manipulated and  explored using conventional methods. For
example, using the standard "orddict" and "proplists" libraries. It is
also possible to define types for Erlson dictionaries and have them
checked by Dialyzer.

Erlson dictionary syntax can be used in both .erl modules and Erlang
shell. Its implementation is based on a customized version of
"erl_parse.yrl", which extends several grammar rules and overloads
existing syntax elements used by Erlang records. Because there was no
need to introduce new syntax elements, the implementation turned out
to be quite simple.

There is a catch, though. The current Erlson implementation is based
on the original "erl_parse.yrl" from R14B03 release. This makes Erlson
incompatible with other Erlang releases if they have a different
version of "erl_parse.yrl".

Although it would be easy to provide Erlson-enabled "erl_parse.yrl"
version for every Erlang release, I was thinking about of a less hacky
and more reliable solution. And this brings me to the question:

Would it be useful if Erlson or some subset/superset of it became a
part of the Erlang language? What do you think?


Anton



More information about the erlang-questions mailing list