Possible bug using funs

Richard Carlsson richardc@REDACTED
Wed Jul 17 17:09:44 CEST 2002


On Wed, 17 Jul 2002, Fredrik Linder wrote:

> Hi, I get the following error when writing a fun:
> 
> 19>
> T1=fun([H1|T1],[H2|T2],Acc,Cont)->io:format("~w~n",[Acc]),Cont(T1,T2,[{H1,H2
> }|Acc],Cont); ([],[],Acc,Cont)->lists:reverse(Acc) end.
> #Fun<erl_eval.3.17583228>
> 20> T1([1,2],[1,2],[],T1).
> []
> [{1,1}]
> ** exited: {{illegal_pattern,{cons,1,{var,1,'H1'},{var,1,'T1'}}},
>             [{erl_eval,expr,3}]} **


There was a bug in erl_eval; I've reported it to OTP. Meanwhile, here is
a patch. (If the pattern was a cons, but the value was not, it resulted
in an illegal pattern error, instead of simply a match failure.)

Index: lib/stdlib/src/erl_eval.erl
===================================================================
631a632,633
> match1({cons,_,H,T}, List, Bs0) ->
>     throw(nomatch);


	/Richard


Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW: http://www.csd.uu.se/~richardc/
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham




More information about the erlang-questions mailing list