[BEGINNER] reccurence! and sequence!

helxi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 26 02:51:17 PDT 2017


Can someone give me a very watered-down explanation of what 
std.range's recurrence! and sequence! do?

> auto tri = sequence!((a,n) => n*(n+1)/2)();

/** okay, it's a triangular number array
* I understand n is the index number, the nth term
* However where does this 'a' go?
*/

> auto odds = sequence!("a[0] + n * a[1]")(1, 2);

/** okay, this is a range of odd numbers
/ where and how do I plug (1, 2) into ""a[0] + n * a[1]"

> sequence!("n+2")(1).take(10).writeln;
//[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
> recurrence!("n+2")(1).take(10).writeln;
//[1, 3, 4, 5, 6, 7, 8, 9, 10, 11]



More information about the Digitalmars-d-learn mailing list