

Lazy Lists in Python and C++ - keveman
http://nonchalantlytyped.net/blog/2011/04/26/lazy-lists-in-different-languages/

======
abecedarius
In Python, I'd normally use a generator: the language and libraries support
you in coding that way. Occasionally you run into the only-iterate-through-
once restriction as a problem, and for that I stick a memoizing adaptor in.

------
RodgerTheGreat
I made a toy implementation of this sort of thing in Forth:

<http://pastebin.com/vHaU3jPW>

This code isn't very well factored, but I think the results are pretty clean
looking. With this code:

    
    
      : printPair ." ( " . ." , " . ." )" space ;
      1 2 counter 0 5 range zip 1 2 counter 3 7 range zip chain ' printPair map
    

You get this output:

    
    
      ( 0 , 1 ) ( 1 , 3 ) ( 2 , 5 ) ( 3 , 7 ) ( 4 , 9 ) ( 5 , 11 )
      ( 3 , 1 ) ( 4 , 3 ) ( 5 , 5 ) ( 6 , 7 ) ( 7 , 9 )

------
nvictor
Lazy title: the author gives examples in Haskell, Python, R, C++, and C++0x.

------
keveman
Is there an explanation of how Python yield is implemented?

~~~
Luyt
Yes. See
[http://docs.python.org/reference/simple_stmts.html#grammar-t...](http://docs.python.org/reference/simple_stmts.html#grammar-
token-yield_stmt) , and the source code is pretty well commented:
[http://svn.python.org/view/python/trunk/Objects/genobject.c?...](http://svn.python.org/view/python/trunk/Objects/genobject.c?view=markup)

