To learn julia, I'm working my way through Project Euler
<https://projecteuler.net/>. For question #2,
<https://projecteuler.net/problem=2> I ran into an issue that I haven't
found a solution to.
Given a function that computes fibonacci numbers:
function fib(n)
a,b = 0,1
while(a < n)
produce(a)
a,b=b,a+b
end
end
I can write a loop that computes the value:
function fibsum(n)
s = 0
for x in Task(() -> fib(n))
if x % 2 == 0
s = s + x
end
end
s
end
fibsum(4000000)
4613732
Analogously, one can write:
s = 0
for x in [1,2,3]
s = s + x
end
println(s)
6
or more succinctly,
sum([x for x in [1,2,3]])
But, when I try that with the fib Task:
sum([x for x in Task(()->fib(10))])
I get
ERROR: `length` has no method matching length(::Task)
in anonymous at no file
Which confuses me sense the task works nicely in an explicit loop.
Regards,
Bill