fun with funs

Ulf Wiger ulf.wiger@REDACTED
Tue Apr 27 12:57:50 CEST 1999


I have a question/discovery that I would like to present:

Every once in a while, the dreaded error message:

{{lambda_clause,mcncServer},{lists,120702597,3}}

appears (mcncServer is just our most recent example.)

This tends to baffle most programmers, and after a few of those, many
try to stay as far away from funs as possible.

Recently, I started looking at the expanded code of a module with funs.

In this particular case, I compiled the mcncServer with 

erlc ... -E mcncServer.erl

I started searching for the fun identified by {lists,120702597,3}.
I first tried searching for 120702597, but with no luck.
Then I searched for the string 'fun%3', and found the following:

{ok,PvcKeys,SpvcKeys} ->
    Job1 = lists:map(make_fun('fun%2'/1, 2, 92415502, []),PvcKeys),
    Job2 = lists:map(make_fun('fun%3'/2, 3, 46622337, []),SpvcKeys),

The funs (1 through 18) are all collected at the end of the file, and
since you can see already from the above that there is something wrong
with 'fun%3' (lists:map/2 expects a fun of arity 1, not 2), I zoomed
down to these two funs:

'fun%2'({Key,ConnType}) ->
    sysTimer:apply_after(1000,mcncServer,poll_timeout,
       [pvc,Key,ConnType,erlang:self()]),
    {pvc,{Key,ConnType}}.
 
'fun%3'(Key,ConnType) ->
    sysTimer:apply_after(1000,mcncServer,poll_timeout,
       [spvc,Key,ConnType,erlang:self()]),
    {spvc,Key,ConnType}.


I think that this method of identifying funs is unique to BEAM, but I
haven't quite figured out how to read it yet. 

- Is the 'lists' reference a way of saying that the fun was called from
the module lists? 

- What exactly does 120702597 stand for?

- How is 3 derived in this case? Does it correspond to 'fun%3', or was I
just lucky this time?

Did I just miss the documentation of this, or isn't there any?

/Uffe
-- 
Ulf Wiger, Chief Designer AXD 301     <ulf.wiger@REDACTED>
Ericsson Telecom AB                          tfn: +46  8 719 81 95
Varuvägen 9, Älvsjö                          mob: +46 70 519 81 95
S-126 25 Stockholm, Sweden                   fax: +46  8 719 43 44



More information about the erlang-questions mailing list