[erlang-questions] How to make this work

Roelof Wobben r.wobben@REDACTED
Wed Aug 12 17:34:16 CEST 2015


Im trying this exercise from the programming erlang book.

Look up the definitions of erlang:now/0, erlang:date/0, and 
erlang:time/0. Write a
function called my_time_func(F), which evaluates the fun F and times how
long it takes.

So I did this :


-export( [time_spend/1] ).

time_spend(F) ->
     Begintime = time:now(),
     Endtime = time:now(),
     Endtime - Begintime.

but then when I do this in erl :

11> my_time:time_spend(fun x -> 2 * X end).
  * 1: syntax error before: '->'
11> my_time:time_spend(Double = fun x -> 2 * X end).
* 1: syntax error before: '->'

how can I make this work ?


Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.

More information about the erlang-questions mailing list