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

Richard O'Keefe <>
Mon Aug 29 08:11:53 CEST 2011


On 29/08/2011, at 6:02 PM, Kostis Sagonas wrote:
> I really do not see how the above quote implies that keys are atoms in proplists.  My reading is that if tuples are used as properties, their keys can actually be any term.  You may be right, but not because of this quote.

I read the proplist documentation the same way Kostis Sagonas does.
Perhaps more importantly, we are told over and over again that
Key = term()
not that Key = atom().

And look at the code for lookup, edited for readability:

lookup(Key, [P | Ps]) ->
    if is_atom(P), P =:= Key ->
            {Key, true}
     ; tuple_size(P) >= 1, element(1, P) =:= Key ->
            %% Note that <code>Key</code> does not have to be an atom in this case.
            P
     ; true ->
            lookup(Key, Ps)
    end;
lookup(_Key, []) ->
    none.

The comment there could hardly be more explicit.

Of course, as explained at length in the proposals and on this mailing list,
the ultra-lightweight "frames"/"proper structs" that Erlang needs ought to
restrict *their* keys to being atoms.





More information about the erlang-questions mailing list