TE
TechEcho
Home
24h Top
Newest
Best
Ask
Show
Jobs
English
GitHub
Twitter
Home
Lazy Lists in Python and C++
8 points
by
keveman
about 14 years ago
4 comments
abecedarius
about 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.
RodgerTheGreat
about 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>
nvictor
about 14 years ago
Lazy title: the author gives examples in Haskell, Python, R, C++, and C++0x.
keveman
about 14 years ago
Collapse
Is there an explanation of how Python yield is implemented?
评论 #2556443 未加载