[erlang-questions] apply/2

David Mercer dmercer@REDACTED
Fri Jul 27 19:25:57 CEST 2007


Bob, I think you misinterpreted.  I wasn't saying that it SHOULD work but
does not.  I was saying it should work AND DOES.  I was showing the original
poster how to modify his statement to get the answer he desires.

That being said, as the poster seems adamant about not specifying the module
name, the following should work AND DOES:

> apply(fun(X) -> round(X) end, [2.3]).

DBM

-----Original Message-----
From: Bob Ippolito [mailto:bob@REDACTED] 
Sent: Friday, July 27, 2007 12:17
To: dmercer@REDACTED
Cc: erlang-questions@REDACTED
Subject: Re: [erlang-questions] apply/2

apply/2 takes a fun, not the name of the function (an atom)... to use
apply/2 you'd do this:

apply(fun erlang:round/1, [2.3]).

apply/3 takes the name of the module, the name of the function (both
atoms), and the arguments as demonstrated.

-bob

On 7/27/07, David Mercer <dmercer@REDACTED> wrote:
> Fun round is in the erlang module.  This should work:
>
> > apply(erlang, round, [2.3]).
>
> Cheers,
>
> David
>
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Henrique
Ferreiro
> Sent: Friday, July 27, 2007 11:42
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] apply/2
>
> Hello,
>
> I noticed some extrange behaviour that this list surely can explain:
>
> 1> round(2.3).
> 2
> 2> apply(round, [2.3]).
>
> =ERROR REPORT==== 27-Jul-2007::18:40:22 ===
> Error in process <0.31.0> with exit value:
>
{{badfun,round},[{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
>
> ** exited: {{badfun,round},
>             [{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
> **
>
> Thanks in advance,
> Henrique Ferreiro
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>




More information about the erlang-questions mailing list