[erlang-questions] Weird function match semantics

Matthew Dempsky matthew@REDACTED
Sun Nov 18 08:14:07 CET 2007

On 17 Nov 2007 10:48:14 +0100, Bjorn Gustavsson <bjorn@REDACTED> wrote:
> It does seems to be a bug in the evaluator. It works fine in
> compiled code. If time permits we will fix it in R12B-0.

The problem I discerned is that $X parses to {char,_,88}, while
erl_eval only expects lists to have integers; this evaluates fine:

    (fun([88] ++ _) -> ok end)("X")

The patch below fixes this for me, and generalizes handling of ++ in
match operations in general.

--- lib/stdlib/src/erl_eval.erl.orig    2007-11-17 23:08:50.000000000 -0800
+++ lib/stdlib/src/erl_eval.erl 2007-11-17 23:09:42.000000000 -0800
@@ -980,8 +980,8 @@
 match1({op,_,'++',{nil,_},R}, Term, Bs, BBs) ->
     match1(R, Term, Bs, BBs);
-match1({op,_,'++',{cons,Li,{integer,L2,I},T},R}, Term, Bs, BBs) ->
-    match1({cons,Li,{integer,L2,I},{op,Li,'++',T,R}}, Term, Bs, BBs);
+match1({op,_,'++',{cons,Li,H,T},R}, Term, Bs, BBs) ->
+    match1({cons,Li,H,{op,Li,'++',T,R}}, Term, Bs, BBs);
 match1({op,_,'++',{string,Li,L},R}, Term, Bs, BBs) ->
     match1(string_to_conses(L, Li, R), Term, Bs, BBs);
 match1({op,Line,Op,A}, Term, Bs, BBs) ->

More information about the erlang-questions mailing list