[erlang-questions] Accessing a single value from MAPS

Fred Hebert <>
Thu Oct 8 16:41:37 CEST 2015

On 10/08, Richard Carlsson wrote:
>Not quite. The end-of-form (or 'dot') token requires that the period
>character is followed by whitespace, a comment, or end-of-file. Otherwise
>it's a '.' token, as is already in use in expressions like
>Once upon a time there was a special syntax called Mnemosyne for writing
>Mnesia queries. To support this, the general form Expr.field was included
>in the grammar (but only had a meaning within a Mnemosyne query). The
>"packages" dotted namespaces piggy-backed on this grammar rule, and when
>packages were removed, this rule was also removed (since Mnemosyne was no
>longer supported either). But it could be put back and reused for maps. In
>fact, I see that it temporarily _was_ used: see f00675d and 703a9aa.

Am I right in assuming mnesmosyne was like records currently are and 
packages were -- mostly using atoms as fields?

There's an interesting distinction for maps in that any data structure·
whatsoever might be a key, even tuples:

5> #{{a,b,c} := _} = #{{a,b,c} => d}.
#{{a,b,c} => d}

which could lead to a dotted notation of the form Map.{a,b,c} which·
frankly looks funny. You can imagine trickier datastructures. Something·
like #{f => #{'d.e' => #{#{=>ok} => ok}}} which would require·

Map.f.'d.e'.#{=>ok} to go fetch the final 'ok'. Either that or you·
support little chaining, but there's still plenty of ways to make this·

At least, it looks like functions are not allowed in there:

7> #{fun() -> a end := _} = #{fun() -> a end => ok}.
* 1: illegal map key in pattern
8> #{fun erlang:exit/2 := _} = #{fun erlang:exit/2 => ok}.
* 1: illegal map key in pattern

But I could still think of fun ways to use term_to_binary in interesting 
ways there.

More information about the erlang-questions mailing list