Looking at this Erlang syntax:
A = #{key1 => Val1, key2 => Val2, ...}
My fingers want to do something like this:
(set a #((=> key1 "value 1") (=> key2 "value 2")))
That feels pretty natural, from the LFE perspective. However, it looks like it might require hacking on the tuple-parsing logic (or splitting that into two code paths: one for regular tuple-parsing, and the other for maps...).
The above syntax also lends itself nicely to these:
(set a #((:= key1 "value 1") (:= key2 "value 2")))
(set a #((=> key1 "value 1") (:= key2 "value 2")))
The question that arises for me is "how would we do this when calling functions?" Perhaps:
(set a (map (=> 'key1 '"value 1")))
(set a (map (:= 'key1 '"value 1")))
Or:
(set a (map (add-pair 'key1 '"value 1")))
(set a (map (update-pair 'key1 '"value 1")))
Then, for Joe's other example:
Z = #{{age, fred} => 12,
{age, bill} => 97,
{color, red} => {rgb, 255, 0, 0}}.
We'd have this for LFE:
(set a #((=> #(age fred) 12)
(=> #(age bill) 97)
Before we pattern match on this, let's look at Erlang pattern matching for tuples:
{Len, Status, Data} = {8, ok, "Trillian"}
Compare this with pattern matching elements of a tuple in LFE.
(set (tuple len status data) #(8 ok "Trillian"))With that in our minds, we turn to Joe's matching example against a specific map element:
#{{color, red} := X1} = Z.
And we could do the same in LFE like this:
(set (map (update-pair (tuple 'color 'red) x1)) z)
I'm *really* uncertain about add-pair and update-pair, both the need for them and the names. Interested to hear from others who know how map is implemented in Erlang and the best way to work with that in LFE...
d