Changing vocabs USING: to reflect which words are in lists and lists.lazy
parent
53daf5504a
commit
0ca627051e
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2007 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: parser-combinators regexp lists lists.lazy sequences kernel
|
||||
USING: parser-combinators regexp lists sequences kernel
|
||||
promises strings unicode.case ;
|
||||
IN: globs
|
||||
|
||||
|
|
|
@ -11,5 +11,5 @@ IN: lazy-lists.examples
|
|||
: odds 1 lfrom [ 2 mod 1 = ] lfilter ;
|
||||
: powers-of-2 1 [ 2 * ] lfrom-by ;
|
||||
: ones 1 [ ] lfrom-by ;
|
||||
: squares naturals [ dup * ] lmap ;
|
||||
: squares naturals [ dup * ] lazy-map ;
|
||||
: first-five-squares 5 squares ltake list>array ;
|
||||
|
|
|
@ -34,9 +34,9 @@ HELP: lazy-map
|
|||
{ $values { "list" "a cons object" } { "quot" "a quotation with stack effect ( obj -- X )" } { "result" "resulting cons object" } }
|
||||
{ $description "Perform a similar functionality to that of the " { $link map } " word, but in a lazy manner. No evaluation of the list elements occurs initially but a " { $link <lazy-map> } " object is returned which conforms to the list protocol. Calling " { $link car } ", " { $link cdr } " or " { $link nil? } " on this will evaluate elements as required." } ;
|
||||
|
||||
HELP: lmap-with
|
||||
HELP: lazy-map-with
|
||||
{ $values { "value" "an object" } { "list" "a cons object" } { "quot" "a quotation with stack effect ( obj elt -- X )" } { "result" "resulting cons object" } }
|
||||
{ $description "Variant of " { $link lmap } " which pushes a retained object on each invocation of the quotation." } ;
|
||||
{ $description "Variant of " { $link lazy-map } " which pushes a retained object on each invocation of the quotation." } ;
|
||||
|
||||
HELP: ltake
|
||||
{ $values { "n" "a non negative integer" } { "list" "a cons object" } { "result" "resulting cons object" } }
|
||||
|
@ -86,7 +86,7 @@ HELP: >list
|
|||
{ $description "Convert the object into a list. Existing lists are passed through intact, sequences are converted using " { $link seq>list } " and other objects cause an error to be thrown." }
|
||||
{ $see-also seq>list } ;
|
||||
|
||||
{ leach lreduce lmap lmap-with ltake lfilter lappend lfrom lfrom-by lconcat lcartesian-product lcartesian-product* lcomp lcomp* lmerge lreduce lwhile luntil } related-words
|
||||
{ leach lreduce lazy-map lazy-map-with ltake lfilter lappend lfrom lfrom-by lconcat lcartesian-product lcartesian-product* lcomp lcomp* lmerge lreduce lwhile luntil } related-words
|
||||
|
||||
HELP: lconcat
|
||||
{ $values { "list" "a list of lists" } { "result" "a list" } }
|
||||
|
|
|
@ -25,5 +25,5 @@ IN: lists.lazy.tests
|
|||
] unit-test
|
||||
|
||||
[ { 4 5 6 } ] [
|
||||
3 { 1 2 3 } >list [ + ] lmap-with list>array
|
||||
3 { 1 2 3 } >list [ + ] lazy-map-with list>array
|
||||
] unit-test
|
||||
|
|
|
@ -9,7 +9,7 @@ IN: lists.tests
|
|||
T{ cons f 2
|
||||
T{ cons f 3
|
||||
T{ cons f 4
|
||||
T{ cons f f f } } } } } [ 2 + ] map-cons
|
||||
T{ cons f f f } } } } } [ 2 + ] lmap
|
||||
] unit-test
|
||||
|
||||
{ 10 } [
|
||||
|
@ -17,5 +17,5 @@ IN: lists.tests
|
|||
T{ cons f 2
|
||||
T{ cons f 3
|
||||
T{ cons f 4
|
||||
T{ cons f f f } } } } } 0 [ + ] reduce-cons
|
||||
T{ cons f f f } } } } } 0 [ + ] lreduce
|
||||
] unit-test
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2007 Samuel Tardieu.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays kernel lists lists.lazy math math.primes namespaces sequences ;
|
||||
USING: arrays kernel lists math math.primes namespaces sequences ;
|
||||
IN: math.primes.factors
|
||||
|
||||
<PRIVATE
|
||||
|
|
|
@ -147,8 +147,8 @@ TUPLE: and-parser parsers ;
|
|||
>r parse-result-parsed r>
|
||||
[ parse-result-parsed 2array ] keep
|
||||
parse-result-unparsed <parse-result>
|
||||
] lmap-with
|
||||
] lmap-with lconcat ;
|
||||
] lazy-map-with
|
||||
] lazy-map-with lconcat ;
|
||||
|
||||
M: and-parser parse ( input parser -- list )
|
||||
#! Parse 'input' by sequentially combining the
|
||||
|
@ -171,7 +171,7 @@ M: or-parser parse ( input parser1 -- list )
|
|||
#! of parser1 and parser2 being applied to the same
|
||||
#! input. This implements the choice parsing operator.
|
||||
or-parser-parsers 0 swap seq>list
|
||||
[ parse ] lmap-with lconcat ;
|
||||
[ parse ] lazy-map-with lconcat ;
|
||||
|
||||
: left-trim-slice ( string -- string )
|
||||
#! Return a new string without any leading whitespace
|
||||
|
@ -216,7 +216,7 @@ M: apply-parser parse ( input parser -- result )
|
|||
-rot parse [
|
||||
[ parse-result-parsed swap call ] keep
|
||||
parse-result-unparsed <parse-result>
|
||||
] lmap-with ;
|
||||
] lazy-map-with ;
|
||||
|
||||
TUPLE: some-parser p1 ;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (c) 2007 Aaron Schaefer.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: lists.lazy math math.primes ;
|
||||
USING: lists math math.primes ;
|
||||
IN: project-euler.007
|
||||
|
||||
! http://projecteuler.net/index.php?section=problems&id=7
|
||||
|
|
Loading…
Reference in New Issue