lazy list

30 views
Skip to first unread message

Derek Frost

unread,
Jun 4, 2017, 2:54:06 PM6/4/17
to yeti-lang
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
take 2 (1 :. [2..9]); // which just hangs.  Maybe I misunderstood ??  :)

//many thanks!

Madis Janson

unread,
Jun 4, 2017, 3:50:05 PM6/4/17
to yeti-lang

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>

Derek Frost

unread,
Jun 5, 2017, 5:33:50 PM6/5/17
to yeti-lang
Actually I figured it out but many thanks for responding!!  I really like the yeti, it's just what I was looking for.  I was using ocaml, but I prefer yeti.

Derek.

Derek Frost

unread,
Jun 8, 2017, 7:05:56 AM6/8/17
to yeti-lang
In your yetiscript pages you say help welcome.  I could translate 'Introduction to Yeti' into French and Esperanto if you're interested??  In 2008 I translated a book by R M Stallman so I've got some experience in translation..  :)

I could also help in other ways but I'm not good at programming, it's just a hobby.



On Sunday, June 4, 2017 at 8:54:06 PM UTC+2, Derek Frost wrote:
Reply all
Reply to author
Forward
0 new messages