TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Lazy Lists in Python and C++

8 pointsby kevemanabout 14 years ago

4 comments

abecedariusabout 14 years ago
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.
RodgerTheGreatabout 14 years ago
I made a toy implementation of this sort of thing in Forth:<p><a href="http://pastebin.com/vHaU3jPW" rel="nofollow">http://pastebin.com/vHaU3jPW</a><p>This code isn't very well factored, but I think the results are pretty clean looking. With this code:<p><pre><code> : printPair ." ( " . ." , " . ." )" space ; 1 2 counter 0 5 range zip 1 2 counter 3 7 range zip chain ' printPair map </code></pre> You get this output:<p><pre><code> ( 0 , 1 ) ( 1 , 3 ) ( 2 , 5 ) ( 3 , 7 ) ( 4 , 9 ) ( 5 , 11 ) ( 3 , 1 ) ( 4 , 3 ) ( 5 , 5 ) ( 6 , 7 ) ( 7 , 9 )</code></pre>
nvictorabout 14 years ago
Lazy title: the author gives examples in Haskell, Python, R, C++, and C++0x.
kevemanabout 14 years ago
Is there an explanation of how Python yield is implemented?
评论 #2556443 未加载