Arity of funs
Bjorn Gustavsson
bjorn@REDACTED
Wed Mar 15 12:13:05 CET 2000
OK, it is of course possible to find out the arity by applying the fun
with different number of arguments and examine the EXIT code.
There will be a badarity exception if the arity was wrong.
This is still not a general solution, since the call may succeed and it may
have unexpected side effects. This might or might not be a problem
depending on what you are trying to achieve in the first place.
What I've learned is that I should be more careful with my words.
I should have written that there is no general, side-effect free way
to obtain the arity of a fun.
/Bjorn
matthias@REDACTED writes:
>
>
> > There is no way to find out the arity of a fun.
>
> I've put a .beam file up at
>
> http://www.ericsson.se/cslab/~mml/besserwisser.beam
>
> Here's what it does:
>
> 4> besserwisser:arity(fun(_) -> a end).
> 1
> 5> besserwisser:arity(fun() -> a end).
> 0
> 6> besserwisser:arity(fun(p,q,r) -> a end).
> 3
>
> How it works is a secret. Looking in the local filesystem is cheating,
> Björn.
>
> Matthias
>
--
Björn Gustavsson Ericsson Utvecklings AB
bjorn@REDACTED ÄT2/UAB/F/P
BOX 1505
+46 8 727 56 87 125 25 Älvsjö
More information about the erlang-questions
mailing list