]> gitweb.factorcode.org Git - factor.git/blob - extra/lists/lazy/examples/examples.factor
Fixing everything for mandatory stack effects
[factor.git] / extra / lists / lazy / examples / examples.factor
1 ! Rewritten by Matthew Willis, July 2006
2 ! Copyright (C) 2004 Chris Double.
3 ! See http://factorcode.org/license.txt for BSD license.
4
5 USING: lists.lazy math kernel sequences quotations ;
6 IN: lists.lazy.examples
7
8 : naturals ( -- list ) 0 lfrom ;
9 : positives ( -- list ) 1 lfrom ;
10 : evens ( -- list ) 0 [ 2 + ] lfrom-by ;
11 : odds ( -- list ) 1 lfrom [ 2 mod 1 = ] lfilter ;
12 : powers-of-2 ( -- list ) 1 [ 2 * ] lfrom-by ;
13 : ones ( -- list ) 1 [ ] lfrom-by ;
14 : squares ( -- list ) naturals [ dup * ] lazy-map ;
15 : first-five-squares ( -- list ) 5 squares ltake list>array ;