Arity of funs

Tony Pedley <>
Wed Mar 15 11:53:28 CET 2000


Hi

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
redfining
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

Tony

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 ()   (This space intentionally left blank.)
> E-mail:       WWW: http://www.csd.uu.se/~richardc/

--
______________________________________________________________________
Tony Pedley             mailto:
Ericsson Intracom Ltd.  Intranet : http://intracom.ericsson.se
1 Bede Island           Internet : http://www.ericsson.co.uk/datacom/index.htm
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: <http://erlang.org/pipermail/erlang-questions/attachments/20000315/cf9d0fe8/attachment.html>


More information about the erlang-questions mailing list