|Passing a fun that executes in repl to another function fails?||Bill Robertson||2/27/11 6:36 PM|
I wrote a timer function which, takes a number of iterations and a
fun, after executing N times, it returns the number of microseconds.
It was doing fine until I gave it the following fun.
168> F = fun() -> gaeqn:evaluate(42,
You can see that the fun executes w/o error, but when passing it to
the timer, something bombs.
170> gaeqn:timer(200, F).
** exception error: bad argument in an arithmetic expression
in function gaeqn:compute/2
in call from gaeqn:evaluate/2
in call from gaeqn:timer/3
The timer code appears to work. Please see the code snippet below.
172> gaeqn:timer(200, fun() -> now() end).
173> N = fun() -> now() end.
174> gaeqn:timer(200, N).
Here is the timer code.
timer(N, Fun) when N > 0 ->
timer(now(), N, Fun).
timer(Start, 0, Fun) ->
timer(Start, N, Fun) ->
timer(Start, N-1, Fun).
Any ideas why the two wouldn't work together?
|Re: Passing a fun that executes in repl to another function fails?||Garrett Smith||2/27/11 10:58 PM|
Does this fail each and every time you run it? You have a "random"
element in your example -- could that be throwing off an occasional
I'd want to know what values were going into gaeqn:compute/2 that were
|Re: Passing a fun that executes in repl to another function fails?||Bill Robertson||2/28/11 8:03 PM|
*sheepish admission* Yup, my problem. Division by zero in there.
Thanks for the help. What is it about learning a new language that
makes figuring out your own problems so difficult? I think you end up
so focused on figuring out about the new stuff that you end up unable
to consider basic problems.
Mon, Feb 28, 2011 at 2:06 AM
>> That's a good point. I had run it a few dozen times w/o error by hand.
>> However, the timer is running it significantly many more times, so
>> probably encountering a flaw in the logic. I will hit it harder tomorrow.
|Re: Passing a fun that executes in repl to another function fails?||jwilberding||3/1/11 3:47 AM|
I have found that with any new language, there is always that period where you to build up your intuition to decipher what an error is being caused by.