From 6fdad74f41803089a0f9026c98f319daecda9a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Thu, 24 Oct 2013 19:06:34 +0200 Subject: erts,stdlib: Change map module name to maps Name conforms to EEP. --- lib/stdlib/src/Makefile | 2 +- lib/stdlib/src/erl_eval.erl | 10 +- lib/stdlib/src/erl_parse.yrl | 2 +- lib/stdlib/src/io_lib.erl | 2 +- lib/stdlib/src/map.erl | 215 ------------------------------------------ lib/stdlib/src/maps.erl | 214 +++++++++++++++++++++++++++++++++++++++++ lib/stdlib/src/stdlib.app.src | 2 +- 7 files changed, 223 insertions(+), 224 deletions(-) delete mode 100644 lib/stdlib/src/map.erl create mode 100644 lib/stdlib/src/maps.erl (limited to 'lib/stdlib') 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/map.erl deleted file mode 100644 index 6257a90180..0000000000 --- a/lib/stdlib/src/map.erl +++ /dev/null @@ -1,215 +0,0 @@ -%% -%% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2013. All Rights Reserved. -%% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. -%% -%% %CopyrightEnd% -%% - --module(map). - --export([ - foldl/3, - foldr/3, - map/2, - size/1, - without/2 - ]). - - -%%% BIFs --export([ - get/2, - find/2, - from_list/1, - is_key/2, - keys/1, - merge/2, - new/0, - put/3, - remove/2, - to_list/1, - update/3, - values/1 - ]). - --type map() :: term(). %% FIXME: remove when erl_bif_types knows map(). - -%% Shadowed by erl_bif_types: map:get/3 --spec get(Key,Map) -> Value when - Key :: term(), - Map :: map(), - Value :: term(). - -get(_,_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:find/3 --spec find(Key,Map) -> {ok, Value} | error when - Key :: term(), - Map :: map(), - Value :: term(). - -find(_,_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:from_list/1 --spec from_list([{Key,Value}]) -> Map when - Key :: term(), - Value :: term(), - Map :: map(). - -from_list(_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:is_key/2 --spec is_key(Key,Map) -> boolean() when - Key :: term(), - Map :: map(). - -is_key(_,_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:keys/1 --spec keys(Map) -> Keys when - Map :: map(), - Keys :: [Key], - Key :: term(). - -keys(_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:merge/2 --spec merge(Map1,Map2) -> Map3 when - Map1 :: map(), - Map2 :: map(), - Map3 :: map(). - -merge(_,_) -> erlang:nif_error(undef). - - - -%% Shadowed by erl_bif_types: map:new/0 --spec new() -> Map when - Map :: map(). - -new() -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:put/3 --spec put(Key,Value,Map1) -> Map2 when - Key :: term(), - Value :: term(), - Map1 :: map(), - Map2 :: map(). - -put(_,_,_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:put/3 --spec remove(Key,Map1) -> Map2 when - Key :: term(), - Map1 :: map(), - Map2 :: map(). - -remove(_,_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:to_list/1 --spec to_list(Map) -> [{Key,Value}] when - Map :: map(), - Key :: term(), - Value :: term(). - -to_list(_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:update/3 --spec update(Key,Value,Map1) -> Map2 when - Key :: term(), - Value :: term(), - Map1 :: map(), - Map2 :: map(). - -update(_,_,_) -> erlang:nif_error(undef). - - -%% Shadowed by erl_bif_types: map:values/1 --spec values(Map) -> Keys when - Map :: map(), - Keys :: [Key], - Key :: term(). - -values(_) -> erlang:nif_error(undef). - - -%%% End of BIFs - --spec foldl(Fun,Init,Map) -> Acc when - Fun :: fun((K, V, AccIn) -> AccOut), - Init :: term(), - Acc :: term(), - AccIn :: term(), - AccOut :: term(), - Map :: map(), - K :: term(), - V :: term(). - -foldl(Fun, Init, Map) -> - lists:foldl(fun({K,V},A) -> Fun(K,V,A) end,Init,map:to_list(Map)). - --spec foldr(Fun,Init,Map) -> Acc when - Fun :: fun((K,V,AccIn) -> AccOut), - Init :: term(), - Acc :: term(), - AccIn :: term(), - AccOut :: term(), - Map :: 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)). - - --spec map(Fun,Map1) -> Map2 when - Fun :: fun((K, V1) -> V2), - Map1 :: map(), - Map2 :: map(), - K :: term(), - V1 :: term(), - V2 :: term(). - - -map(Fun, Map) -> - map:from_list(lists:map(fun - ({K,V}) -> - {K,Fun(K,V)} - end,map:to_list(Map))). - --spec size(Map) -> non_neg_integer() when - Map :: map(). - -size(Map) -> - erlang:map_size(Map). - --spec without(Ks,Map1) -> Map2 when - Ks :: [K], - Map1 :: map(), - Map2 :: map(), - K :: term(). - -without(Ks, M) -> - map:from_list([{K,V}||{K,V} <- map:to_list(M), not lists:member(K, Ks)]). diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl new file mode 100644 index 0000000000..218dc28bec --- /dev/null +++ b/lib/stdlib/src/maps.erl @@ -0,0 +1,214 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2013. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(maps). + +-export([ + foldl/3, + foldr/3, + map/2, + size/1, + without/2 + ]). + + +%%% BIFs +-export([ + get/2, + find/2, + from_list/1, + is_key/2, + keys/1, + merge/2, + new/0, + put/3, + remove/2, + to_list/1, + update/3, + values/1 + ]). + +-type map() :: term(). %% FIXME: remove when erl_bif_types knows map(). + +%% Shadowed by erl_bif_types: maps:get/3 +-spec get(Key,Map) -> Value when + Key :: term(), + Map :: map(), + Value :: term(). + +get(_,_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:find/3 +-spec find(Key,Map) -> {ok, Value} | error when + Key :: term(), + Map :: map(), + Value :: term(). + +find(_,_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:from_list/1 +-spec from_list([{Key,Value}]) -> Map when + Key :: term(), + Value :: term(), + Map :: map(). + +from_list(_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:is_key/2 +-spec is_key(Key,Map) -> boolean() when + Key :: term(), + Map :: map(). + +is_key(_,_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:keys/1 +-spec keys(Map) -> Keys when + Map :: map(), + Keys :: [Key], + Key :: term(). + +keys(_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:merge/2 +-spec merge(Map1,Map2) -> Map3 when + Map1 :: map(), + Map2 :: map(), + Map3 :: map(). + +merge(_,_) -> erlang:nif_error(undef). + + + +%% Shadowed by erl_bif_types: maps:new/0 +-spec new() -> Map when + Map :: map(). + +new() -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:put/3 +-spec put(Key,Value,Map1) -> Map2 when + Key :: term(), + Value :: term(), + Map1 :: map(), + Map2 :: map(). + +put(_,_,_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:put/3 +-spec remove(Key,Map1) -> Map2 when + Key :: term(), + Map1 :: map(), + Map2 :: map(). + +remove(_,_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:to_list/1 +-spec to_list(Map) -> [{Key,Value}] when + Map :: map(), + Key :: term(), + Value :: term(). + +to_list(_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:update/3 +-spec update(Key,Value,Map1) -> Map2 when + Key :: term(), + Value :: term(), + Map1 :: map(), + Map2 :: map(). + +update(_,_,_) -> erlang:nif_error(undef). + + +%% Shadowed by erl_bif_types: maps:values/1 +-spec values(Map) -> Keys when + Map :: map(), + Keys :: [Key], + Key :: term(). + +values(_) -> erlang:nif_error(undef). + + +%%% End of BIFs + +-spec foldl(Fun,Init,Map) -> Acc when + Fun :: fun((K, V, AccIn) -> AccOut), + Init :: term(), + Acc :: term(), + AccIn :: term(), + AccOut :: term(), + Map :: map(), + K :: term(), + V :: term(). + +foldl(Fun, Init, 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), + Init :: term(), + Acc :: term(), + AccIn :: term(), + AccOut :: term(), + Map :: map(), + K :: term(), + V :: term(). + +foldr(Fun, Init, Map) -> + lists:foldr(fun({K,V},A) -> Fun(K,V,A) end,Init,maps:to_list(Map)). + + +-spec map(Fun,Map1) -> Map2 when + Fun :: fun((K, V1) -> V2), + Map1 :: map(), + Map2 :: map(), + K :: term(), + V1 :: term(), + V2 :: term(). + +map(Fun, Map) -> + maps:from_list(lists:map(fun + ({K,V}) -> + {K,Fun(K,V)} + end,maps:to_list(Map))). + + +-spec size(Map) -> non_neg_integer() when + Map :: map(). + +size(Map) -> + erlang:map_size(Map). + +-spec without(Ks,Map1) -> Map2 when + Ks :: [K], + Map1 :: map(), + Map2 :: map(), + K :: term(). + +without(Ks, M) -> + 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, -- cgit v1.2.3