Arity of funs

Tony Rogvall tony@REDACTED
Wed Mar 15 13:01:24 CET 2000


matthias@REDACTED wrote:

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

Try this:
besserwisser:arity(fn:f(1))
and see how the besser works (read NOT) :-)

also try besserwisser:arity(fn:f(5))

---------
-module(fn).

-compile(export_all).

f(0) -> fun() ->  erlang:display(besserwisser) end;
f(1) -> fun(A) ->  erlang:display(besserwisser) end;
f(2) -> fun(A,B) ->  erlang:display(besserwisser) end;
f(3) -> fun(A,B,C) ->  erlang:display(besserwisser) end;
f(4) -> fun(A,B,C,D) -> erlang:display(besserwisser) end;
f(5) -> fun(x,x,x,x,x) -> erlang:display(besserwisser) end.

--------

/Tony





More information about the erlang-questions mailing list