[erlang-questions] Where is the syntax error.

Hugo Mills <>
Thu Sep 24 18:17:01 CEST 2015


On Thu, Sep 24, 2015 at 06:05:13PM +0200, Roelof Wobben wrote:
> Op 24-9-2015 om 17:01 schreef Garry Hodgson:
> >On 09/24/2015 08:54 AM, zxq9 wrote:
> >>Debugging all day makes me bad at find-it-yourself hints... -Craig _
> >
> >I like to split my time between putting bugs in and taking them out.
> >
> 
> Thanks,
> 
> One thing I do not see.
> 
> If I want to run this with a function with a argument.
> 
> -module(time).
> 
> -export([elapsed_time/1]).
> 
> elapsed_time(F) ->
>     Begintime = erlang:monotonic_time(),
>     F(),
>     Endtime = erlang:monotonic_time(),
>     Time = erlang:convert_time_unit(Endtime - Begintime,native ,
> micro_seconds),
>     io:format("This took ~w microseconds", [Time]).
> 
> This is the wrong way to do this :
> 
> time:elapsed_time((Answer = fun(x) -> x + 2 end )2).
> 
> Can I solve this by chancing the function to this elapsed_time(F,
> arg)  and then do F(arg) ?

   Yes, exactly. Although you probably want to use Arg (variable), not
arg (atom) :)

   Hugo.

> Roelof
> 
> time:elapsed_time((Answer = fun(x) -> x + 2 end )2).
> 
> time:elapsed_time((Answer = fun(x) -> x + 2 end )2).
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-- 
Hugo Mills             | Putting U back in Honor, Valor, and Trth.
 carfax.org.uk |
http://carfax.org.uk/  |
PGP: E2AB1DE4          |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150924/bd3061f0/attachment.bin>


More information about the erlang-questions mailing list