aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--erts/emulator/beam/bif.tab24
-rw-r--r--erts/emulator/beam/erl_map.c82
-rw-r--r--erts/emulator/test/map_SUITE.erl248
-rw-r--r--lib/stdlib/src/Makefile2
-rw-r--r--lib/stdlib/src/erl_eval.erl10
-rw-r--r--lib/stdlib/src/erl_parse.yrl2
-rw-r--r--lib/stdlib/src/io_lib.erl2
-rw-r--r--lib/stdlib/src/maps.erl (renamed from lib/stdlib/src/map.erl)39
-rw-r--r--lib/stdlib/src/stdlib.app.src2
9 files changed, 205 insertions, 206 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab
index 306861a4c5..b623e47b9a 100644
--- a/erts/emulator/beam/bif.tab
+++ b/erts/emulator/beam/bif.tab
@@ -580,18 +580,18 @@ bif re:inspect/2
ubif erlang:is_map/1
ubif erlang:map_size/1
-bif map:to_list/1
-bif map:find/2
-bif map:get/2
-bif map:from_list/1
-bif map:is_key/2
-bif map:keys/1
-bif map:merge/2
-bif map:new/0
-bif map:put/3
-bif map:remove/2
-bif map:update/3
-bif map:values/1
+bif maps:to_list/1
+bif maps:find/2
+bif maps:get/2
+bif maps:from_list/1
+bif maps:is_key/2
+bif maps:keys/1
+bif maps:merge/2
+bif maps:new/0
+bif maps:put/3
+bif maps:remove/2
+bif maps:update/3
+bif maps:values/1
#
# Obsolete
diff --git a/erts/emulator/beam/erl_map.c b/erts/emulator/beam/erl_map.c
index 6fd60f0689..27734276f9 100644
--- a/erts/emulator/beam/erl_map.c
+++ b/erts/emulator/beam/erl_map.c
@@ -38,25 +38,25 @@
* - erlang:is_map/1
* - erlang:map_size/1
*
- * - map:find/2
- * - map:from_list/1
- * - map:get/2
- * - map:is_key/2
- * - map:keys/1
- * - map:merge/2
- * - map:new/0
- * - map:put/3
- * - map:remove/2
- * - map:to_list/1
- * - map:update/3
- * - map:values/1
+ * - maps:find/2
+ * - maps:from_list/1
+ * - maps:get/2
+ * - maps:is_key/2
+ * - maps:keys/1
+ * - maps:merge/2
+ * - maps:new/0
+ * - maps:put/3
+ * - maps:remove/2
+ * - maps:to_list/1
+ * - maps:update/3
+ * - maps:values/1
*
* TODO:
- * - map:foldl/3
- * - map:foldr/3
- * - map:map/3
- * - map:size/1
- * - map:without/2
+ * - maps:foldl/3
+ * - maps:foldr/3
+ * - maps:map/3
+ * - maps:size/1
+ * - maps:without/2
*
*/
@@ -80,10 +80,10 @@ BIF_RETTYPE map_size_1(BIF_ALIST_1) {
BIF_ERROR(BIF_P, BADARG);
}
-/* map:to_list/1
+/* maps:to_list/1
*/
-BIF_RETTYPE map_to_list_1(BIF_ALIST_1) {
+BIF_RETTYPE maps_to_list_1(BIF_ALIST_1) {
if (is_map(BIF_ARG_1)) {
Uint n;
Eterm* hp;
@@ -107,11 +107,11 @@ BIF_RETTYPE map_to_list_1(BIF_ALIST_1) {
BIF_ERROR(BIF_P, BADARG);
}
-/* map:find/2
+/* maps:find/2
* return value if key *equals* a key in the map
*/
-BIF_RETTYPE map_find_2(BIF_ALIST_2) {
+BIF_RETTYPE maps_find_2(BIF_ALIST_2) {
if (is_map(BIF_ARG_2)) {
Eterm *hp, *ks,*vs, key, res;
map_t *mp;
@@ -137,12 +137,12 @@ BIF_RETTYPE map_find_2(BIF_ALIST_2) {
}
BIF_ERROR(BIF_P, BADARG);
}
-/* map:get/2
+/* maps:get/2
* return value if key *matches* a key in the map
* exception bad_key if none matches
*/
-BIF_RETTYPE map_get_2(BIF_ALIST_2) {
+BIF_RETTYPE maps_get_2(BIF_ALIST_2) {
if (is_map(BIF_ARG_2)) {
Eterm *hp, *ks,*vs, key, error;
map_t *mp;
@@ -184,11 +184,11 @@ error:
BIF_ERROR(BIF_P, BADARG);
}
-/* map:from_list/1
+/* maps:from_list/1
* List may be unsorted [{K,V}]
*/
-BIF_RETTYPE map_from_list_1(BIF_ALIST_1) {
+BIF_RETTYPE maps_from_list_1(BIF_ALIST_1) {
Eterm *kv, item = BIF_ARG_1;
Eterm *hp, *thp,*vs, *ks, keys, res;
map_t *mp;
@@ -305,10 +305,10 @@ error:
BIF_ERROR(BIF_P, BADARG);
}
-/* map:is_key/2
+/* maps:is_key/2
*/
-BIF_RETTYPE map_is_key_2(BIF_ALIST_2) {
+BIF_RETTYPE maps_is_key_2(BIF_ALIST_2) {
if (is_map(BIF_ARG_2)) {
Eterm *ks, key;
map_t *mp;
@@ -340,10 +340,10 @@ BIF_RETTYPE map_is_key_2(BIF_ALIST_2) {
BIF_ERROR(BIF_P, BADARG);
}
-/* map:keys/1
+/* maps:keys/1
*/
-BIF_RETTYPE map_keys_1(BIF_ALIST_1) {
+BIF_RETTYPE maps_keys_1(BIF_ALIST_1) {
if (is_map(BIF_ARG_1)) {
Eterm *hp, *ks, res = NIL;
map_t *mp;
@@ -366,10 +366,10 @@ BIF_RETTYPE map_keys_1(BIF_ALIST_1) {
}
BIF_ERROR(BIF_P, BADARG);
}
-/* map:merge/2
+/* maps:merge/2
*/
-BIF_RETTYPE map_merge_2(BIF_ALIST_2) {
+BIF_RETTYPE maps_merge_2(BIF_ALIST_2) {
if (is_map(BIF_ARG_1) && is_map(BIF_ARG_2)) {
Eterm *hp,*thp;
Eterm tup;
@@ -452,10 +452,10 @@ BIF_RETTYPE map_merge_2(BIF_ALIST_2) {
}
BIF_ERROR(BIF_P, BADARG);
}
-/* map:new/2
+/* maps:new/2
*/
-BIF_RETTYPE map_new_0(BIF_ALIST_0) {
+BIF_RETTYPE maps_new_0(BIF_ALIST_0) {
Eterm* hp;
Eterm tup;
map_t *mp;
@@ -472,10 +472,10 @@ BIF_RETTYPE map_new_0(BIF_ALIST_0) {
BIF_RET(make_map(mp));
}
-/* map:put/3
+/* maps:put/3
*/
-BIF_RETTYPE map_put_3(BIF_ALIST_3) {
+BIF_RETTYPE maps_put_3(BIF_ALIST_3) {
if (is_map(BIF_ARG_3)) {
Sint n,i;
Sint c = 0;
@@ -582,10 +582,10 @@ BIF_RETTYPE map_put_3(BIF_ALIST_3) {
BIF_ERROR(BIF_P, BADARG);
}
-/* map:remove/3
+/* maps:remove/3
*/
-BIF_RETTYPE map_remove_2(BIF_ALIST_2) {
+BIF_RETTYPE maps_remove_2(BIF_ALIST_2) {
if (is_map(BIF_ARG_2)) {
Sint n;
Sint found = 0;
@@ -656,10 +656,10 @@ BIF_RETTYPE map_remove_2(BIF_ALIST_2) {
BIF_ERROR(BIF_P, BADARG);
}
-/* map:update/3
+/* maps:update/3
*/
-BIF_RETTYPE map_update_3(BIF_ALIST_3) {
+BIF_RETTYPE maps_update_3(BIF_ALIST_3) {
if (is_map(BIF_ARG_3)) {
Sint n,i;
Sint found = 0;
@@ -719,10 +719,10 @@ BIF_RETTYPE map_update_3(BIF_ALIST_3) {
}
-/* map:values/1
+/* maps:values/1
*/
-BIF_RETTYPE map_values_1(BIF_ALIST_1) {
+BIF_RETTYPE maps_values_1(BIF_ALIST_1) {
if (is_map(BIF_ARG_1)) {
Eterm *hp, *vs, res = NIL;
map_t *mp;
diff --git a/erts/emulator/test/map_SUITE.erl b/erts/emulator/test/map_SUITE.erl
index 69b68c4b67..59fdb82f50 100644
--- a/erts/emulator/test/map_SUITE.erl
+++ b/erts/emulator/test/map_SUITE.erl
@@ -412,182 +412,182 @@ t_map_sort_literals(Config) when is_list(Config) ->
%% BIFs
t_bif_map_get(Config) when is_list(Config) ->
- 1 = map:get(a, #{ a=> 1}),
- 2 = map:get(b, #{ a=> 1, b => 2}),
- "hi" = map:get("hello", #{ a=>1, "hello" => "hi"}),
- "tuple hi" = map:get({1,1.0}, #{ a=>a, {1,1.0} => "tuple hi"}),
+ 1 = maps:get(a, #{ a=> 1}),
+ 2 = maps:get(b, #{ a=> 1, b => 2}),
+ "hi" = maps:get("hello", #{ a=>1, "hello" => "hi"}),
+ "tuple hi" = maps:get({1,1.0}, #{ a=>a, {1,1.0} => "tuple hi"}),
M = id(#{ k1=>"v1", <<"k2">> => <<"v3">> }),
- "v4" = map:get(<<"k2">>, M#{ <<"k2">> => "v4" }),
+ "v4" = maps:get(<<"k2">>, M#{ <<"k2">> => "v4" }),
%% error case
- {'EXIT',{badarg,[{map,get,_,_}|_]}} = (catch map:get(a,[])),
- {'EXIT',{badarg,[{map,get,_,_}|_]}} = (catch map:get(a,<<>>)),
- {'EXIT',{bad_key,[{map,get,_,_}|_]}} = (catch map:get({1,1}, #{{1,1.0} => "tuple"})),
- {'EXIT',{bad_key,[{map,get,_,_}|_]}} = (catch map:get(a,#{})),
- {'EXIT',{bad_key,[{map,get,_,_}|_]}} = (catch map:get(a,#{ b=>1, c=>2})),
+ {'EXIT',{badarg, [{maps,get,_,_}|_]}} = (catch maps:get(a,[])),
+ {'EXIT',{badarg, [{maps,get,_,_}|_]}} = (catch maps:get(a,<<>>)),
+ {'EXIT',{bad_key,[{maps,get,_,_}|_]}} = (catch maps:get({1,1}, #{{1,1.0} => "tuple"})),
+ {'EXIT',{bad_key,[{maps,get,_,_}|_]}} = (catch maps:get(a,#{})),
+ {'EXIT',{bad_key,[{maps,get,_,_}|_]}} = (catch maps:get(a,#{ b=>1, c=>2})),
ok.
t_bif_map_find(Config) when is_list(Config) ->
- {ok, 1} = map:find(a, #{ a=> 1}),
- {ok, 2} = map:find(b, #{ a=> 1, b => 2}),
- {ok, "int"} = map:find(1, #{ 1 => "int"}),
- {ok, "int"} = map:find(1.0, #{ 1 => "int"}),
- {ok, "float"} = map:find(1, #{ 1.0 => "float"}),
- {ok, "float"} = map:find(1.0, #{ 1.0=> "float"}),
+ {ok, 1} = maps:find(a, #{ a=> 1}),
+ {ok, 2} = maps:find(b, #{ a=> 1, b => 2}),
+ {ok, "int"} = maps:find(1, #{ 1 => "int"}),
+ {ok, "int"} = maps:find(1.0, #{ 1 => "int"}),
+ {ok, "float"} = maps:find(1, #{ 1.0 => "float"}),
+ {ok, "float"} = maps:find(1.0, #{ 1.0=> "float"}),
- {ok, "hi"} = map:find("hello", #{ a=>1, "hello" => "hi"}),
- {ok, "tuple hi"} = map:find({1.0,1}, #{ a=>a, {1,1.0} => "tuple hi"}), % reverse types in tuple key
+ {ok, "hi"} = maps:find("hello", #{ a=>1, "hello" => "hi"}),
+ {ok, "tuple hi"} = maps:find({1.0,1}, #{ a=>a, {1,1.0} => "tuple hi"}), % reverse types in tuple key
M = id(#{ k1=>"v1", <<"k2">> => <<"v3">> }),
- {ok, "v4"} = map:find(<<"k2">>, M#{ <<"k2">> => "v4" }),
+ {ok, "v4"} = maps:find(<<"k2">>, M#{ <<"k2">> => "v4" }),
%% error case
- error = map:find(a,#{}),
- error = map:find(a,#{b=>1, c=>2}),
+ error = maps:find(a,#{}),
+ error = maps:find(a,#{b=>1, c=>2}),
- {'EXIT',{badarg,[{map,find,_,_}|_]}} = (catch map:find(a,[])),
- {'EXIT',{badarg,[{map,find,_,_}|_]}} = (catch map:find(a,<<>>)),
+ {'EXIT',{badarg,[{maps,find,_,_}|_]}} = (catch maps:find(a,[])),
+ {'EXIT',{badarg,[{maps,find,_,_}|_]}} = (catch maps:find(a,<<>>)),
ok.
t_bif_map_is_key(Config) when is_list(Config) ->
M1 = #{ "hi" => "hello", int => 3, <<"key">> => <<"value">>, 4 => number},
- true = map:is_key("hi", M1),
- true = map:is_key(int, M1),
- true = map:is_key(<<"key">>, M1),
- true = map:is_key(4, M1),
-
- false = map:is_key(5, M1),
- false = map:is_key(<<"key2">>, M1),
- false = map:is_key("h", M1),
- false = map:is_key("hello", M1),
- false = map:is_key(atom, M1),
-
- false = map:is_key("hi", map:remove("hi", M1)),
- true = map:is_key("hi", M1),
- true = map:is_key(1, map:put(1, "number", M1)),
- false = map:is_key(1.0, map:put(1, "number", M1)),
+ true = maps:is_key("hi", M1),
+ true = maps:is_key(int, M1),
+ true = maps:is_key(<<"key">>, M1),
+ true = maps:is_key(4, M1),
+
+ false = maps:is_key(5, M1),
+ false = maps:is_key(<<"key2">>, M1),
+ false = maps:is_key("h", M1),
+ false = maps:is_key("hello", M1),
+ false = maps:is_key(atom, M1),
+
+ false = maps:is_key("hi", maps:remove("hi", M1)),
+ true = maps:is_key("hi", M1),
+ true = maps:is_key(1, maps:put(1, "number", M1)),
+ false = maps:is_key(1.0, maps:put(1, "number", M1)),
ok.
t_bif_map_keys(Config) when is_list(Config) ->
- [] = map:keys(#{}),
+ [] = maps:keys(#{}),
- [1,2,3,4,5] = map:keys(#{ 1 => a, 2 => b, 3 => c, 4 => d, 5 => e}),
- [1,2,3,4,5] = map:keys(#{ 4 => d, 5 => e, 1 => a, 2 => b, 3 => c}),
+ [1,2,3,4,5] = maps:keys(#{ 1 => a, 2 => b, 3 => c, 4 => d, 5 => e}),
+ [1,2,3,4,5] = maps:keys(#{ 4 => d, 5 => e, 1 => a, 2 => b, 3 => c}),
% values in key order: [4,int,"hi",<<"key">>]
M1 = #{ "hi" => "hello", int => 3, <<"key">> => <<"value">>, 4 => number},
- [4,int,"hi",<<"key">>] = map:keys(M1),
+ [4,int,"hi",<<"key">>] = maps:keys(M1),
%% error case
- {'EXIT',{badarg,[{map,keys,_,_}|_]}} = (catch map:keys(1 bsl 65 + 3)),
- {'EXIT',{badarg,[{map,keys,_,_}|_]}} = (catch map:keys(154)),
- {'EXIT',{badarg,[{map,keys,_,_}|_]}} = (catch map:keys(atom)),
- {'EXIT',{badarg,[{map,keys,_,_}|_]}} = (catch map:keys([])),
- {'EXIT',{badarg,[{map,keys,_,_}|_]}} = (catch map:keys(<<>>)),
+ {'EXIT',{badarg,[{maps,keys,_,_}|_]}} = (catch maps:keys(1 bsl 65 + 3)),
+ {'EXIT',{badarg,[{maps,keys,_,_}|_]}} = (catch maps:keys(154)),
+ {'EXIT',{badarg,[{maps,keys,_,_}|_]}} = (catch maps:keys(atom)),
+ {'EXIT',{badarg,[{maps,keys,_,_}|_]}} = (catch maps:keys([])),
+ {'EXIT',{badarg,[{maps,keys,_,_}|_]}} = (catch maps:keys(<<>>)),
ok.
t_bif_map_new(Config) when is_list(Config) ->
- #{} = map:new(),
- 0 = erlang:map_size(map:new()),
+ #{} = maps:new(),
+ 0 = erlang:map_size(maps:new()),
ok.
t_bif_map_put(Config) when is_list(Config) ->
M0 = #{ "hi" => "hello", int => 3, <<"key">> => <<"value">>,
4 => number, 18446744073709551629 => wat},
- M1 = #{ "hi" := "hello"} = map:put("hi", "hello", #{}),
+ M1 = #{ "hi" := "hello"} = maps:put("hi", "hello", #{}),
- ["hi"] = map:keys(M1),
- ["hello"] = map:values(M1),
+ ["hi"] = maps:keys(M1),
+ ["hello"] = maps:values(M1),
- M2 = #{ int := 3 } = map:put(int, 3, M1),
+ M2 = #{ int := 3 } = maps:put(int, 3, M1),
- [int,"hi"] = map:keys(M2),
- [3,"hello"] = map:values(M2),
+ [int,"hi"] = maps:keys(M2),
+ [3,"hello"] = maps:values(M2),
- M3 = #{ <<"key">> := <<"value">> } = map:put(<<"key">>, <<"value">>, M2),
+ M3 = #{ <<"key">> := <<"value">> } = maps:put(<<"key">>, <<"value">>, M2),
- [int,"hi",<<"key">>] = map:keys(M3),
- [3,"hello",<<"value">>] = map:values(M3),
+ [int,"hi",<<"key">>] = maps:keys(M3),
+ [3,"hello",<<"value">>] = maps:values(M3),
- M4 = #{ 18446744073709551629 := wat } = map:put(18446744073709551629, wat, M3),
+ M4 = #{ 18446744073709551629 := wat } = maps:put(18446744073709551629, wat, M3),
- [18446744073709551629,int,"hi",<<"key">>] = map:keys(M4),
- [wat,3,"hello",<<"value">>] = map:values(M4),
+ [18446744073709551629,int,"hi",<<"key">>] = maps:keys(M4),
+ [wat,3,"hello",<<"value">>] = maps:values(M4),
- M0 = #{ 4 := number } = M5 = map:put(4, number, M4),
+ M0 = #{ 4 := number } = M5 = maps:put(4, number, M4),
- [4,18446744073709551629,int,"hi",<<"key">>] = map:keys(M5),
- [number,wat,3,"hello",<<"value">>] = map:values(M5),
+ [4,18446744073709551629,int,"hi",<<"key">>] = maps:keys(M5),
+ [number,wat,3,"hello",<<"value">>] = maps:values(M5),
%% error case
- {'EXIT',{badarg,[{map,put,_,_}|_]}} = (catch map:put(1,a,1 bsl 65 + 3)),
- {'EXIT',{badarg,[{map,put,_,_}|_]}} = (catch map:put(1,a,154)),
- {'EXIT',{badarg,[{map,put,_,_}|_]}} = (catch map:put(1,a,atom)),
- {'EXIT',{badarg,[{map,put,_,_}|_]}} = (catch map:put(1,a,[])),
- {'EXIT',{badarg,[{map,put,_,_}|_]}} = (catch map:put(1,a,<<>>)),
+ {'EXIT',{badarg,[{maps,put,_,_}|_]}} = (catch maps:put(1,a,1 bsl 65 + 3)),
+ {'EXIT',{badarg,[{maps,put,_,_}|_]}} = (catch maps:put(1,a,154)),
+ {'EXIT',{badarg,[{maps,put,_,_}|_]}} = (catch maps:put(1,a,atom)),
+ {'EXIT',{badarg,[{maps,put,_,_}|_]}} = (catch maps:put(1,a,[])),
+ {'EXIT',{badarg,[{maps,put,_,_}|_]}} = (catch maps:put(1,a,<<>>)),
ok.
t_bif_map_remove(Config) when is_list(Config) ->
M0 = #{ "hi" => "hello", int => 3, <<"key">> => <<"value">>,
4 => number, 18446744073709551629 => wat},
- M1 = map:remove("hi", M0),
- [4,18446744073709551629,int,<<"key">>] = map:keys(M1),
- [number,wat,3,<<"value">>] = map:values(M1),
+ M1 = maps:remove("hi", M0),
+ [4,18446744073709551629,int,<<"key">>] = maps:keys(M1),
+ [number,wat,3,<<"value">>] = maps:values(M1),
- M2 = map:remove(int, M1),
- [4,18446744073709551629,<<"key">>] = map:keys(M2),
- [number,wat,<<"value">>] = map:values(M2),
+ M2 = maps:remove(int, M1),
+ [4,18446744073709551629,<<"key">>] = maps:keys(M2),
+ [number,wat,<<"value">>] = maps:values(M2),
- M3 = map:remove(<<"key">>, M2),
- [4,18446744073709551629] = map:keys(M3),
- [number,wat] = map:values(M3),
+ M3 = maps:remove(<<"key">>, M2),
+ [4,18446744073709551629] = maps:keys(M3),
+ [number,wat] = maps:values(M3),
- M4 = map:remove(18446744073709551629, M3),
- [4] = map:keys(M4),
- [number] = map:values(M4),
+ M4 = maps:remove(18446744073709551629, M3),
+ [4] = maps:keys(M4),
+ [number] = maps:values(M4),
- M5 = map:remove(4, M4),
- [] = map:keys(M5),
- [] = map:values(M5),
+ M5 = maps:remove(4, M4),
+ [] = maps:keys(M5),
+ [] = maps:values(M5),
- M0 = map:remove(5,M0),
- M0 = map:remove("hi there",M0),
+ M0 = maps:remove(5,M0),
+ M0 = maps:remove("hi there",M0),
- #{ "hi" := "hello", int := 3, 4 := number} = map:remove(18446744073709551629,map:remove(<<"key">>,M0)),
+ #{ "hi" := "hello", int := 3, 4 := number} = maps:remove(18446744073709551629,maps:remove(<<"key">>,M0)),
%% error case
- {'EXIT',{badarg,[{map,remove,_,_}|_]}} = (catch map:remove(a,1 bsl 65 + 3)),
- {'EXIT',{badarg,[{map,remove,_,_}|_]}} = (catch map:remove(1,154)),
- {'EXIT',{badarg,[{map,remove,_,_}|_]}} = (catch map:remove(a,atom)),
- {'EXIT',{badarg,[{map,remove,_,_}|_]}} = (catch map:remove(1,[])),
- {'EXIT',{badarg,[{map,remove,_,_}|_]}} = (catch map:remove(a,<<>>)),
+ {'EXIT',{badarg,[{maps,remove,_,_}|_]}} = (catch maps:remove(a,1 bsl 65 + 3)),
+ {'EXIT',{badarg,[{maps,remove,_,_}|_]}} = (catch maps:remove(1,154)),
+ {'EXIT',{badarg,[{maps,remove,_,_}|_]}} = (catch maps:remove(a,atom)),
+ {'EXIT',{badarg,[{maps,remove,_,_}|_]}} = (catch maps:remove(1,[])),
+ {'EXIT',{badarg,[{maps,remove,_,_}|_]}} = (catch maps:remove(a,<<>>)),
ok.
t_bif_map_values(Config) when is_list(Config) ->
- [] = map:values(#{}),
+ [] = maps:values(#{}),
- [a,b,c,d,e] = map:values(#{ 1 => a, 2 => b, 3 => c, 4 => d, 5 => e}),
- [a,b,c,d,e] = map:values(#{ 4 => d, 5 => e, 1 => a, 2 => b, 3 => c}),
+ [a,b,c,d,e] = maps:values(#{ 1 => a, 2 => b, 3 => c, 4 => d, 5 => e}),
+ [a,b,c,d,e] = maps:values(#{ 4 => d, 5 => e, 1 => a, 2 => b, 3 => c}),
% values in key order: [4,int,"hi",<<"key">>]
M1 = #{ "hi" => "hello", int => 3, <<"key">> => <<"value">>, 4 => number},
M2 = M1#{ "hi" => "hello2", <<"key">> => <<"value2">> },
- [number,3,"hello2",<<"value2">>] = map:values(M2),
- [number,3,"hello",<<"value">>] = map:values(M1),
+ [number,3,"hello2",<<"value2">>] = maps:values(M2),
+ [number,3,"hello",<<"value">>] = maps:values(M1),
%% error case
- {'EXIT',{badarg,[{map,values,_,_}|_]}} = (catch map:values(1 bsl 65 + 3)),
- {'EXIT',{badarg,[{map,values,_,_}|_]}} = (catch map:values(atom)),
- {'EXIT',{badarg,[{map,values,_,_}|_]}} = (catch map:values([])),
- {'EXIT',{badarg,[{map,values,_,_}|_]}} = (catch map:values(<<>>)),
+ {'EXIT',{badarg,[{maps,values,_,_}|_]}} = (catch maps:values(1 bsl 65 + 3)),
+ {'EXIT',{badarg,[{maps,values,_,_}|_]}} = (catch maps:values(atom)),
+ {'EXIT',{badarg,[{maps,values,_,_}|_]}} = (catch maps:values([])),
+ {'EXIT',{badarg,[{maps,values,_,_}|_]}} = (catch maps:values(<<>>)),
ok.
t_erlang_hash(Config) when is_list(Config) ->
@@ -610,7 +610,7 @@ t_bif_erlang_phash2() ->
44049159 = erlang:phash2(#{<<>> => {}}),
M0 = #{ a => 1, "key" => <<"value">> },
- M1 = map:remove("key",M0),
+ M1 = maps:remove("key",M0),
M2 = M1#{ "key" => <<"value">> },
118679416 = erlang:phash2(M0),
@@ -630,7 +630,7 @@ t_bif_erlang_phash() ->
1578050717 = erlang:phash(#{<<>> => {}},Sz), % yep, broken
M0 = #{ a => 1, "key" => <<"value">> },
- M1 = map:remove("key",M0),
+ M1 = maps:remove("key",M0),
M2 = M1#{ "key" => <<"value">> },
3590546636 = erlang:phash(M0,Sz),
@@ -650,7 +650,7 @@ t_bif_erlang_hash() ->
101655720 = erlang:hash(#{<<>> => {}},Sz), % yep, broken
M0 = #{ a => 1, "key" => <<"value">> },
- M1 = map:remove("key",M0),
+ M1 = maps:remove("key",M0),
M2 = M1#{ "key" => <<"value">> },
38260486 = erlang:hash(M0,Sz),
@@ -706,7 +706,7 @@ t_map_encode_decode(Config) when is_list(Config) ->
ok.
map_encode_decode_and_match([{K,V}|Pairs], EncodedPairs, M0) ->
- M1 = map:put(K,V,M0),
+ M1 = maps:put(K,V,M0),
B0 = erlang:term_to_binary(M1),
Ls = lists:sort([{K, erlang:term_to_binary(K), erlang:term_to_binary(V)}|EncodedPairs]),
%% sort Ks and Vs according to term spec, then match it
@@ -729,45 +729,45 @@ match_encoded_map(Bin,[<<131,Item/binary>>|Items]) ->
t_bif_map_to_list(Config) when is_list(Config) ->
- [] = map:to_list(#{}),
- [{a,1},{b,2}] = map:to_list(#{a=>1,b=>2}),
- [{a,1},{b,2},{c,3}] = map:to_list(#{c=>3,a=>1,b=>2}),
- [{a,1},{b,2},{g,3}] = map:to_list(#{g=>3,a=>1,b=>2}),
- [{a,1},{b,2},{g,3},{"c",4}] = map:to_list(#{g=>3,a=>1,b=>2,"c"=>4}),
- [{3,v2},{hi,v4},{{hi,3},v5},{"hi",v3},{<<"hi">>,v1}] = map:to_list(#{
+ [] = maps:to_list(#{}),
+ [{a,1},{b,2}] = maps:to_list(#{a=>1,b=>2}),
+ [{a,1},{b,2},{c,3}] = maps:to_list(#{c=>3,a=>1,b=>2}),
+ [{a,1},{b,2},{g,3}] = maps:to_list(#{g=>3,a=>1,b=>2}),
+ [{a,1},{b,2},{g,3},{"c",4}] = maps:to_list(#{g=>3,a=>1,b=>2,"c"=>4}),
+ [{3,v2},{hi,v4},{{hi,3},v5},{"hi",v3},{<<"hi">>,v1}] = maps:to_list(#{
<<"hi">>=>v1,3=>v2,"hi"=>v3,hi=>v4,{hi,3}=>v5}),
- [{3,v7},{hi,v9},{{hi,3},v10},{"hi",v8},{<<"hi">>,v6}] = map:to_list(#{
+ [{3,v7},{hi,v9},{{hi,3},v10},{"hi",v8},{<<"hi">>,v6}] = maps:to_list(#{
<<"hi">>=>v1,3=>v2,"hi"=>v3,hi=>v4,{hi,3}=>v5,
<<"hi">>=>v6,3=>v7,"hi"=>v8,hi=>v9,{hi,3}=>v10}),
%% error cases
- {'EXIT', {badarg,_}} = (catch map:to_list(id(a))),
- {'EXIT', {badarg,_}} = (catch map:to_list(id(42))),
+ {'EXIT', {badarg,_}} = (catch maps:to_list(id(a))),
+ {'EXIT', {badarg,_}} = (catch maps:to_list(id(42))),
ok.
t_bif_map_from_list(Config) when is_list(Config) ->
- #{} = map:from_list([]),
- A = map:from_list([]),
+ #{} = maps:from_list([]),
+ A = maps:from_list([]),
0 = erlang:map_size(A),
- #{a:=1,b:=2} = map:from_list([{a,1},{b,2}]),
- #{c:=3,a:=1,b:=2} = map:from_list([{a,1},{b,2},{c,3}]),
- #{g:=3,a:=1,b:=2} = map:from_list([{a,1},{b,2},{g,3}]),
+ #{a:=1,b:=2} = maps:from_list([{a,1},{b,2}]),
+ #{c:=3,a:=1,b:=2} = maps:from_list([{a,1},{b,2},{c,3}]),
+ #{g:=3,a:=1,b:=2} = maps:from_list([{a,1},{b,2},{g,3}]),
- #{a:=2} = map:from_list([{a,1},{a,3},{a,2}]),
+ #{a:=2} = maps:from_list([{a,1},{a,3},{a,2}]),
#{ <<"hi">>:=v1,3:=v3,"hi":=v6,hi:=v4,{hi,3}:=v5} =
- map:from_list([{3,v3},{"hi",v6},{hi,v4},{{hi,3},v5},{<<"hi">>,v1}]),
+ maps:from_list([{3,v3},{"hi",v6},{hi,v4},{{hi,3},v5},{<<"hi">>,v1}]),
#{<<"hi">>:=v6,3:=v8,"hi":=v11,hi:=v9,{hi,3}:=v10} =
- map:from_list([ {{hi,3},v3}, {"hi",v0},{3,v1}, {<<"hi">>,v4}, {hi,v2},
+ maps:from_list([ {{hi,3},v3}, {"hi",v0},{3,v1}, {<<"hi">>,v4}, {hi,v2},
{<<"hi">>,v6}, {{hi,3},v10},{"hi",v11}, {hi,v9}, {3,v8}]),
%% error cases
- {'EXIT', {badarg,_}} = (catch map:from_list(id(a))),
- {'EXIT', {badarg,_}} = (catch map:from_list(id(42))),
+ {'EXIT', {badarg,_}} = (catch maps:from_list(id(a))),
+ {'EXIT', {badarg,_}} = (catch maps:from_list(id(42))),
ok.
%% MISC
diff --git a/lib/stdlib/src/Makefile b/lib/stdlib/src/Makefile
index 376083c7d6..9ab2cd4134 100644
--- a/lib/stdlib/src/Makefile
+++ b/lib/stdlib/src/Makefile
@@ -91,7 +91,7 @@ MODULES= \
lib \
lists \
log_mf_h \
- map \
+ maps \
math \
ms_transform \
otp_internal \
diff --git a/lib/stdlib/src/erl_eval.erl b/lib/stdlib/src/erl_eval.erl
index fcd1945c63..5f96795d92 100644
--- a/lib/stdlib/src/erl_eval.erl
+++ b/lib/stdlib/src/erl_eval.erl
@@ -253,14 +253,14 @@ expr({map,_, Binding,Es}, Bs0, Lf, Ef, RBs) ->
{value, Map0, Bs1} = expr(Binding, Bs0, Lf, Ef, RBs),
{Vs,Bs} = expr_list(Es, Bs1, Lf, Ef),
ret_expr(lists:foldl(fun
- ({map_assoc,K,V}, Mi) -> map:put(K,V,Mi);
- ({map_exact,K,V}, Mi) -> map:update(K,V,Mi)
+ ({map_assoc,K,V}, Mi) -> maps:put(K,V,Mi);
+ ({map_exact,K,V}, Mi) -> maps:update(K,V,Mi)
end, Map0, Vs), Bs, RBs);
expr({map,_,Es}, Bs0, Lf, Ef, RBs) ->
{Vs,Bs} = expr_list(Es, Bs0, Lf, Ef),
ret_expr(lists:foldl(fun
- ({map_assoc,K,V}, Mi) -> map:put(K,V,Mi)
- end, map:new(), Vs), Bs, RBs);
+ ({map_assoc,K,V}, Mi) -> maps:put(K,V,Mi)
+ end, maps:new(), Vs), Bs, RBs);
expr({block,_,Es}, Bs, Lf, Ef, RBs) ->
exprs(Es, Bs, Lf, Ef, RBs);
@@ -1148,7 +1148,7 @@ match_tuple([], _, _, Bs, _BBs) ->
match_map([{map_field_exact, _, K, V}|Fs], Map, Bs0, BBs) ->
Vm = try
{value, Ke, _} = expr(K, new_bindings()),
- map:get(Ke,Map)
+ maps:get(Ke,Map)
catch error:_ ->
throw(nomatch)
end,
diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl
index 6d9aafa980..6316db7054 100644
--- a/lib/stdlib/src/erl_parse.yrl
+++ b/lib/stdlib/src/erl_parse.yrl
@@ -896,7 +896,7 @@ normalise({cons,_,Head,Tail}) ->
normalise({tuple,_,Args}) ->
list_to_tuple(normalise_list(Args));
normalise({map,_,Pairs}=M) ->
- map:from_list(lists:map(fun
+ maps:from_list(lists:map(fun
%% only allow '=>'
({map_field_assoc,_,K,V}) -> {normalise(K),normalise(V)};
(_) -> erlang:error({badarg,M})
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl
index 886939761c..adc9a0cf5f 100644
--- a/lib/stdlib/src/io_lib.erl
+++ b/lib/stdlib/src/io_lib.erl
@@ -278,7 +278,7 @@ write_ref(Ref) ->
erlang:ref_to_list(Ref).
write_map(Map, D) when is_integer(D) ->
- [$#,${,write_map_body(map:to_list(Map), D),$}].
+ [$#,${,write_map_body(maps:to_list(Map), D),$}].
write_map_body(_, 0) -> "...";
write_map_body([],_) -> [];
diff --git a/lib/stdlib/src/map.erl b/lib/stdlib/src/maps.erl
index 6257a90180..218dc28bec 100644
--- a/lib/stdlib/src/map.erl
+++ b/lib/stdlib/src/maps.erl
@@ -17,7 +17,7 @@
%% %CopyrightEnd%
%%
--module(map).
+-module(maps).
-export([
foldl/3,
@@ -46,7 +46,7 @@
-type map() :: term(). %% FIXME: remove when erl_bif_types knows map().
-%% Shadowed by erl_bif_types: map:get/3
+%% Shadowed by erl_bif_types: maps:get/3
-spec get(Key,Map) -> Value when
Key :: term(),
Map :: map(),
@@ -55,7 +55,7 @@
get(_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:find/3
+%% Shadowed by erl_bif_types: maps:find/3
-spec find(Key,Map) -> {ok, Value} | error when
Key :: term(),
Map :: map(),
@@ -64,7 +64,7 @@ get(_,_) -> erlang:nif_error(undef).
find(_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:from_list/1
+%% Shadowed by erl_bif_types: maps:from_list/1
-spec from_list([{Key,Value}]) -> Map when
Key :: term(),
Value :: term(),
@@ -73,7 +73,7 @@ find(_,_) -> erlang:nif_error(undef).
from_list(_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:is_key/2
+%% Shadowed by erl_bif_types: maps:is_key/2
-spec is_key(Key,Map) -> boolean() when
Key :: term(),
Map :: map().
@@ -81,7 +81,7 @@ from_list(_) -> erlang:nif_error(undef).
is_key(_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:keys/1
+%% Shadowed by erl_bif_types: maps:keys/1
-spec keys(Map) -> Keys when
Map :: map(),
Keys :: [Key],
@@ -90,7 +90,7 @@ is_key(_,_) -> erlang:nif_error(undef).
keys(_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:merge/2
+%% Shadowed by erl_bif_types: maps:merge/2
-spec merge(Map1,Map2) -> Map3 when
Map1 :: map(),
Map2 :: map(),
@@ -100,14 +100,14 @@ merge(_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:new/0
+%% Shadowed by erl_bif_types: maps:new/0
-spec new() -> Map when
Map :: map().
new() -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:put/3
+%% Shadowed by erl_bif_types: maps:put/3
-spec put(Key,Value,Map1) -> Map2 when
Key :: term(),
Value :: term(),
@@ -117,7 +117,7 @@ new() -> erlang:nif_error(undef).
put(_,_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:put/3
+%% Shadowed by erl_bif_types: maps:put/3
-spec remove(Key,Map1) -> Map2 when
Key :: term(),
Map1 :: map(),
@@ -126,7 +126,7 @@ put(_,_,_) -> erlang:nif_error(undef).
remove(_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:to_list/1
+%% Shadowed by erl_bif_types: maps:to_list/1
-spec to_list(Map) -> [{Key,Value}] when
Map :: map(),
Key :: term(),
@@ -135,7 +135,7 @@ remove(_,_) -> erlang:nif_error(undef).
to_list(_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:update/3
+%% Shadowed by erl_bif_types: maps:update/3
-spec update(Key,Value,Map1) -> Map2 when
Key :: term(),
Value :: term(),
@@ -145,7 +145,7 @@ to_list(_) -> erlang:nif_error(undef).
update(_,_,_) -> erlang:nif_error(undef).
-%% Shadowed by erl_bif_types: map:values/1
+%% Shadowed by erl_bif_types: maps:values/1
-spec values(Map) -> Keys when
Map :: map(),
Keys :: [Key],
@@ -167,7 +167,7 @@ values(_) -> erlang:nif_error(undef).
V :: term().
foldl(Fun, Init, Map) ->
- lists:foldl(fun({K,V},A) -> Fun(K,V,A) end,Init,map:to_list(Map)).
+ lists:foldl(fun({K,V},A) -> Fun(K,V,A) end,Init,maps:to_list(Map)).
-spec foldr(Fun,Init,Map) -> Acc when
Fun :: fun((K,V,AccIn) -> AccOut),
@@ -179,9 +179,8 @@ foldl(Fun, Init, Map) ->
K :: term(),
V :: term().
-
foldr(Fun, Init, Map) ->
- lists:foldr(fun({K,V},A) -> Fun(K,V,A) end,Init,map:to_list(Map)).
+ lists:foldr(fun({K,V},A) -> Fun(K,V,A) end,Init,maps:to_list(Map)).
-spec map(Fun,Map1) -> Map2 when
@@ -192,12 +191,12 @@ foldr(Fun, Init, Map) ->
V1 :: term(),
V2 :: term().
-
map(Fun, Map) ->
- map:from_list(lists:map(fun
+ maps:from_list(lists:map(fun
({K,V}) ->
{K,Fun(K,V)}
- end,map:to_list(Map))).
+ end,maps:to_list(Map))).
+
-spec size(Map) -> non_neg_integer() when
Map :: map().
@@ -212,4 +211,4 @@ size(Map) ->
K :: term().
without(Ks, M) ->
- map:from_list([{K,V}||{K,V} <- map:to_list(M), not lists:member(K, Ks)]).
+ maps:from_list([{K,V}||{K,V} <- maps:to_list(M), not lists:member(K, Ks)]).
diff --git a/lib/stdlib/src/stdlib.app.src b/lib/stdlib/src/stdlib.app.src
index 9a77ae9d66..a64b8e13c0 100644
--- a/lib/stdlib/src/stdlib.app.src
+++ b/lib/stdlib/src/stdlib.app.src
@@ -71,7 +71,7 @@
lib,
lists,
log_mf_h,
- map,
+ maps,
math,
ms_transform,
orddict,