what happens if i apply a Fun on a empty list

Håkan Stenholm hakan.stenholm@REDACTED
Fri Aug 5 01:55:30 CEST 2005


>Res = apply(Fun, [])
>What will be in Res? will it have the return value of
>or something is wrong with the above statement?
The above is ok and will contain the result of the call to "Fun()" call 
in Res, i.e. if the call is a call to a valid function things will look 
like below:

%% call math:pi()

1> apply(fun math:pi/0, []).

%% call lists:append([1,2,3],[4,5,6])

2> apply(fun lists:append/2, [[1,2,3],[4,5,6]]).

If the call is to a non-existent function like in the example below ( 
lists:append() ), there will instead be a runtime execption.

3> apply(fun lists:append/2, []).              

=ERROR REPORT==== 5-Aug-2005::01:39:26 ===
Error in process <0.30.0> with exit value: 

** exited: {{badarity,{#Fun<lists.append.2>,[]}},
            [{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]} **

Documentation about apply and funs is available in the "erlang" module 
and in the "Erlang Reference Manual" page chapter 6.17 

There are also more info about funs in Programming Examples chapter 2

>Do you Yahoo!? 
>Read only the mail you want - Yahoo! Mail SpamGuard. 

More information about the erlang-questions mailing list