[erlang-questions] Maps

Ola Bäckström Ola.Backstrom@REDACTED
Thu May 16 08:30:54 CEST 2013


Correction: It was Chris King that wrote what  I cited below. I cut away the wrong part, sorry for the confusion.

After reading the EPP I see that similar functions to B and C are called Update and Put but just acts on one pair at a time.

-----Original Message-----
From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Ola Bäckström
Sent: den 15 maj 2013 17:15
To: Erlang
Subject: Re: [erlang-questions] Maps


> On Wed, 15 May 2013 04:20:20 -0400, Jesper Louis Andersen <jesper.louis.andersen@REDACTED> wrote:
[snip]
> I understand that.  But why must (a) this new fast map implementation 
> have an associated syntax, and (b) this syntax displace the syntax 
> which *is* needed to implement pattern-matching of frames?

Could the syntax somehow be decoupled from the implementation, allowing for usage in both scenarios?
I just played with the idea a  little... so assume the map implementation is found in the module 'coolmap' 

A) To create a map, one would have to point out what implementation module that should do the job.

M = coolmap#{foo => 1, bar => 2, baz =>3}.
	Since coolmap is an atom, the compiler knows this must be creation of a new map... thus translated to M= coolmap:create([{foo, 1},{bar, 2}, {baz, 3}]).

The variable M should somewhere contain the module name, so that a call extract_module(M) returns coolmap.

B) To update a map, 

M2 = M#{foo := 12}.
 	Since M isn't an atom the compiler understands that this translates to M2= (extract_module(M)):update([{foo, 12}], M).

C) To introduce new keys

M3 = M2#{foo:=100, bary => 24}
	The Since => is used in the expression this will be translated to another function:
M2= (extract_module(M2)):edit([{update, foo, 100},{set, foo, 12}], M2).

The above would allow anybody to create new implementations, could it be useful to allow Frames and Maps to share syntax?

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list