[erlang-questions] maps and lager: how to handle new type gracefully?

Loïc Hoguin <>
Tue Apr 29 17:14:56 CEST 2014


On 04/29/2014 05:02 PM, Luca Favatella wrote:
> Loïc Hoguin wrote:
>  > erlang:function_exported(erlang, is_map, 1) can tell you if it exists
> before you try to call it.
>
> Max Lapshin wrote:
>  > huh, rather complicated, but ok, it will work.
>
> Hi,
>
> I think it doesn't because is_map is a BIF, thus function_exported
> returns false even if the is_map function is there.
>
>  From http://www.erlang.org/doc/man/erlang.html#function_exported-3:
> "Returns false for any BIF (functions implemented in C rather than in
> Erlang)."
>
>
> Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:4:4] [async-threads:10]
> [hipe] [kernel-poll:false]
>
> Eshell V6.0  (abort with ^G)
> 1> erlang:function_exported(erlang, is_map, 1).
> false
> 2> erlang:is_map(1).
> false
>
>
> Erlang R15B03 (erts-5.9.3.1) [source] [64-bit] [smp:4:4]
> [async-threads:0] [kernel-poll:false]
>
> Eshell V5.9.3.1  (abort with ^G)
> 1> erlang:function_exported(erlang, is_map, 1).
> false
> 2> erlang:function_exported(erlang, is_list, 1).
> false
> 3> erlang:is_list(1).
> false

Nice find. Then second best thing: check if the maps module exists. :-)

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list