Proposed change to libraries

Kostis Sagonas kostis@REDACTED
Mon Feb 7 13:07:43 CET 2005


Bjorn Gustvsson wrote:
 > I have some good news and some bad news. :-)
 >
 > The good news is that we can change lists:map/2 and friends in
 > R10B-4 to reject an F that is not a fun. That is merely a bug fix
 > and does not break backward compatibility.
 > 
 > The bad news is that F must be allowed to be a "tuple fun" too,
 > to keep backward compatibility.
 > 
 > Thus the revised code must look like this:
 > 
 > map(F, [H|T]) ->
 >   [F(H)|map(F, T)];
 > map(F, []) when is_function(F) -> %% andalso is_fun_arity(F) == 1
 >   [];
 > map({M,F}, []) when is_atom(M), is_atom(F) ->
 >   [].

I totally understand the argument for maintaining backwards compatibility,
even though I do not fully agree with it, but if the decision is to add
the extra clause, there is still something which is needed.

Besides checking that M and F are atoms, there needs to be a check that
the {M,F} is a valid fun object and its arity is 1 (note the is_fun_arity
new guard that is required in the second clause -- I wrote it as a comment
but it really needs to be introduced in the language for the type inference
algorithm to infer that the F in the first and the second clause are of
the same type).

Kostis




More information about the erlang-questions mailing list