1 ! Rewritten by Matthew Willis, July 2006
2 ! Copyright (C) 2004 Chris Double.
3 ! See http://factorcode.org/license.txt for BSD license.
5 USING: lists.lazy math kernel sequences quotations ;
6 IN: lists.lazy.examples
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 ;