what happens if i apply a Fun on a empty list

Ulf Wiger ulf@REDACTED
Fri Aug 5 02:04:38 CEST 2005


Den 2005-08-05 01:23:52 skrev MEENA SELVAM <meena_selvam@REDACTED>:

> Res = apply(Fun, [])
>
> What will be in Res? will it have the return value of
> function;
>
> or something is wrong with the above statement?
>
> meena

Nothing like a little experimentation:

Eshell V5.4.8  (abort with ^G)
1> apply(fun() -> foo end, []).
foo
2> apply(fun(X) -> foo end, []).
** exited: {{badarity,{#Fun<erl_eval.6.10732646>,[]}},[{erl_eval,expr,3}]}  
**
3>

What apply(Fun, []) means is "apply Fun()", i.e. with no
arguments. If Fun is a function of arity 0, then it will
work, otherwise not.

/Uffe

-- 
Ulf Wiger



More information about the erlang-questions mailing list