[BEGINNER] reccurence! and sequence!

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 6 10:51:49 PDT 2017


On 07/06/2017 02:21 AM, Ali Çehreli wrote:
> On 07/05/2017 04:38 PM, helxi wrote:
[...]
>  >> recurrence!((a, n) => a[0] + 1)(1).take(10).writeln;
>  > 1. In the last example of reccurence, what does n in (a,n) refer to?
> 
> n is "the index of the current value". Each time the lambda is called,
> 
>    a[n] is what is being generated
>    a[n-1] is the previous value
>    a[0] is the same as a[n-1]? (I find this confusing)

Looks like I was wrong when I stated that "a[0] refers to the previous 
value". `a[0]` is actually invalid for n > 1.

The documentation for `recurrence` says you have to index relative to n, 
and you can only go back as many values as you gave initially. I should 
have used `a[n - 1]`.


More information about the Digitalmars-d-learn mailing list