[erlang-questions] How to make this work

Roberto Ostinelli roberto@REDACTED
Wed Aug 12 17:44:11 CEST 2015


You're just missing proper parenthesis.

my_time:time_spend(fun(X) -> 2 * X end).

BTW there isn't such thing as time:now().


On Wed, Aug 12, 2015 at 5:42 PM, Roelof Wobben <r.wobben@REDACTED> wrote:

> Hello,
>
> According to the Programming Erlang book second edition this is the proper
> syntax.
>
> Double = fun X -> X * 2 end.
>
> Roelof
>
>
> Op 12-8-2015 om 17:38 schreef Garry Hodgson:
>
> read the documentation on the proper syntax for defining funs.
>>
>> On 8/12/15 11:34 AM, Roelof Wobben wrote:
>>
>>> Hello,
>>>
>>> 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 :
>>>
>>> -module(my_time).
>>>
>>> -export( [time_spend/1] ).
>>>
>>> time_spend(F) ->
>>>     Begintime = time:now(),
>>>     F(3),
>>>     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 ?
>>>
>>> Roelof
>>>
>>>
>>> ---
>>> Dit e-mailbericht is gecontroleerd op virussen met Avast
>>> antivirussoftware.
>>> https://www.avast.com/antivirus
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
> ---
> Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
> https://www.avast.com/antivirus
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150812/27a70c2c/attachment.htm>


More information about the erlang-questions mailing list