[erlang-questions] map module functions, map "cons" idea

Lukas Larsson lukas@REDACTED
Mon Aug 4 10:05:57 CEST 2014


Hello Daniel!

Thanks for taking the time to write down your ideas and suggestions.

On Thu, Jul 31, 2014 at 9:28 PM, Daniel Goertzen <daniel.goertzen@REDACTED>
wrote:

>
> 1. I ported a few functions from the lists module.  The ones I found
> useful were filter() and mapfold().  I also found with() useful, which does
> the opposite of maps:without().  I would be very happy to see these 3
> functions in the maps module.
>

I too see the usefulness of these functions. I'll bring it up with the
resident expert.


>
>
> 2. In the talk there was a question about matching an empty map, and also
> a question about precise matching like how one would match a list.  I have
> always wondered similar things, so it got me thinking…
>
> What if we use a "cons" in a map pattern to allow matching all remaining
> keys that were not selected in the main part of the pattern?  This would be
> roughly symmetric to what you can do with lists and binaries.  For example:
>
> #{ a:=A, c:=C | Rest } = #{a=>1, b=>2, c=>3, d=>4}.   % Rest = #{b=>2,
> d=>4}
>
>
> That in itself I think has limited use, but it could be used to exactly
> match a map (ie, no extra pairs other than those specified in the match):
>
> f(#{ a:=A, c:=C | Rest })
>
>   when maps:size(Rest)==0 ->
>
>>
>
> If the pattern to the right of the bar is elided, we could take it to mean
> “match the empty map”.  The previous example could be rewritten as:
>
> f(#{ a:=A, c:=C |}) ->
>
>>
>
> This also lets you match just the empty map as was asked in the talk:
>
> f(#{|}) ->
>
>>
>
>
Richard O'Keefe had something very similar to this in his proposal for how
frames should work in Erlang. You can find the details here:
http://www.cs.otago.ac.nz/staffpriv/ok/frames.pdf. We have been talking
about doing something like this, but want to stabilize and polish off the
current feature set before doing any more work on the syntax.

Lukas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140804/86daeddd/attachment.htm>


More information about the erlang-questions mailing list