[erlang-questions] Maps

Ola Bäckström Ola.Backstrom@REDACTED
Wed May 15 17:15:10 CEST 2013

> On Wed, 15 May 2013 04:20:20 -0400, Jesper Louis Andersen <jesper.louis.andersen@REDACTED> wrote:
> 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?

More information about the erlang-questions mailing list