Arity of funs

Tony Pedley tonyp@REDACTED
Wed Mar 15 11:53:28 CET 2000


We are using a block test server here which I am not sure is supported but is pretty simple.
You define stubs of functions which are either not written yet or external to your block e.g

bt:stub_fun_def(module,function,fun(A,B) -> ok end)

These are stored on a ETS table and if during the running of the code a undef error is raised,
the table is searched and the fun called instead.

However it appears that the ETS table key is {module,function} so if we the same functions but with
2 arity values
there is no way of indicating the difference in the table so the fun may fail because of incorrect
number of
parameters depending on which is stored.

What we really require is the key to be {module,function,arity} and while that could be acheived by
the stub_fun_def function to be like

bt:stub_fun_def(module,function,arity,fun(A,B) -> ok end)

this would not be very backward compatible with everyones block tests, so what would be better is
for the
stub_fun_def function to be able to extract the funs arity when it is called and the the undef error
handler would extract
the required arity from the undef error message and call the correct fun.

Anyway add a feature and people will use it!

All the best


Richard Carlsson wrote:

> On Wed, 15 Mar 2000, Tony Pedley wrote:
> > Hi,
> > Well I've searched the OTP book, trawled the erlang questions
> > archive(very good by the way, however there should be an all button on
> > the Available Subdirectories) and I still can't work out how to do it.
> >
> > How do you extract the arity of a Fun? e.g How do I do this
> >
> > F = fun(X,Y,Z) -> end,
> >
> > X = get_fun_arity(F).
> >
> > 3
> You don't, I'm sure. Sorry.
> 1: Neither the old representation of funs as tuples, nor the new
> representation in R6 contain the arity. (The BIF erlang:fun_info/1 can
> give you some information "for debugging purposes only", but not the
> arity.)
> 2. Even if you know the module where the source code resides, and the
> fun-table index of a particular fun, there is no way to ask the module
> what the arity of that fun is (short of disassembling the compiled code).
> Out of curiosity: why do you want to find the arity of an arbitrary fun?
>         /Richard Carlsson
> Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
> E-mail: Richard.Carlsson@REDACTED      WWW:

Tony Pedley             mailto:tonyp@REDACTED
Ericsson Intracom Ltd.  Intranet :
1 Bede Island           Internet :
Leicester               memoID  : ECOM.CBERAM
England                 Tel  : +44 (0)116 2 542 400
LE2 7EU                 Fax  : +44 (0)116 2 046 111

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list