On Sun, 4 Jun 2017, Derek Frost wrote:
> Please could someone give a very basic example of a lazy list just to point me in the right direction??
> I have done this:
> (:.) v l = v :. l; //from the website then this
Thus you overrode the :. operator with one that recursively calls itself.
Same as f v l = f v l; because there is no (end) condition, it is endless loop.
The std.yeti module has similar definition - with norec keyword:
norec (:.) v l = v :. l;
The norec means no recursive binding, therefore using compilers inbuilt
:. definition (to provide actual lambda binding).
> take 2 (1 :. [2..9]); // which just hangs. Maybe I misunderstood ?? :)
Thats the endless recursion of previous :. definition.
Without it a compiler error is given:
1:14: Cannot apply (() -> list?<number>) -> list<number> function to list<number> argument
This is because :. expects lambda generating the tail list as second argument.
> take 2 (1 :. \[2..9])
[1,2] is list<number>