how implement takeWhile
Simen Kjaeraas
simen.kjaras at gmail.com
Mon Aug 6 02:59:29 PDT 2012
On Mon, 06 Aug 2012 11:53:18 +0200, bioinfornatics
<bioinfornatics at gmail.com> wrote:
> Dear,
> 1/
>
> i would like have a code near as this haskell code:
>
> fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
>
> main = do
> print $ sum (filter even (takeWhile (<4000000) fibs))
>
>
>
>
> Ii know in D:
> - auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1);
> - std.algorithm.until
> - std.algorithm.filler
> - std.algorithm.reduce
> - std.range.InputRange.popFront
> - std.range.take
> - std.array.appender
>
> but i do not see how to these feature together to have a code
> close to the haskell code.
>
> Someone?
>
> 2/
> Someone know to generate a fibonacci list directly with a lambda
> syyntax and not from string ("a[n-1] + a[n-2]") ?
>
> thanks
This is what you want, isn't it?
recurrence!((a,n)=>a[n-1]+a[n-2])(1,1).until!(a=>a>=40000)()
--
Simen
More information about the Digitalmars-d-learn
mailing list