lazy-lists: modify examples
parent
668a9cf878
commit
d4091e03c6
|
@ -27,7 +27,7 @@ USING: lazy-lists math kernel sequences test ;
|
||||||
IN: lazy-examples
|
IN: lazy-examples
|
||||||
|
|
||||||
: naturals 0 lfrom ;
|
: naturals 0 lfrom ;
|
||||||
: positves 1 lfrom ;
|
: positives 1 lfrom ;
|
||||||
: evens 0 [ 2 + ] lfrom-by ;
|
: evens 0 [ 2 + ] lfrom-by ;
|
||||||
: odds 1 lfrom [ 2 mod 1 = ] lsubset ;
|
: odds 1 lfrom [ 2 mod 1 = ] lsubset ;
|
||||||
: powers-of-2 1 [ 2 * ] lfrom-by ;
|
: powers-of-2 1 [ 2 * ] lfrom-by ;
|
||||||
|
@ -43,6 +43,7 @@ IN: lazy-examples
|
||||||
#! Given a lazy list of numbers, filter multiples of n
|
#! Given a lazy list of numbers, filter multiples of n
|
||||||
swap [ divisible-by? not ] curry lsubset ;
|
swap [ divisible-by? not ] curry lsubset ;
|
||||||
|
|
||||||
: primes 2 lfrom [ filter-multiples ] lapply ;
|
: primes ( -- list )
|
||||||
|
2 lfrom [ filter-multiples ] lapply ;
|
||||||
|
|
||||||
: first-ten-primes 10 primes ltake list>array ;
|
: first-ten-primes 10 primes ltake list>array ;
|
Loading…
Reference in New Issue