diff --git a/core/bootstrap/image/image.factor b/core/bootstrap/image/image.factor index 4468ecf7d1..7c12b3ea60 100755 --- a/core/bootstrap/image/image.factor +++ b/core/bootstrap/image/image.factor @@ -7,7 +7,7 @@ strings sbufs vectors words quotations assocs system layouts splitting growable classes tuples words.private io.binary io.files vocabs vocabs.loader source-files definitions debugger float-arrays quotations.private -combinators.private combinators ; +sequences.private combinators ; IN: bootstrap.image : my-arch ( -- arch ) diff --git a/core/combinators/combinators-docs.factor b/core/combinators/combinators-docs.factor old mode 100644 new mode 100755 index 4cea78bc97..d91c920def --- a/core/combinators/combinators-docs.factor +++ b/core/combinators/combinators-docs.factor @@ -1,6 +1,6 @@ USING: arrays help.markup help.syntax strings sbufs vectors kernel quotations generic generic.standard classes -math assocs sequences combinators.private ; +math assocs sequences sequences.private ; IN: combinators ARTICLE: "combinators-quot" "Quotation construction utilities" diff --git a/core/combinators/combinators.factor b/core/combinators/combinators.factor index f532f06293..0ba8b583be 100755 --- a/core/combinators/combinators.factor +++ b/core/combinators/combinators.factor @@ -4,12 +4,6 @@ IN: combinators USING: arrays sequences sequences.private math.private kernel kernel.private math assocs quotations vectors ; - - TUPLE: no-cond ; : no-cond ( -- * ) \ no-cond construct-empty throw ; diff --git a/core/compiler/tests/intrinsics.factor b/core/compiler/tests/intrinsics.factor index 679938b7f3..5dfe447443 100755 --- a/core/compiler/tests/intrinsics.factor +++ b/core/compiler/tests/intrinsics.factor @@ -4,7 +4,7 @@ math.private sequences strings tools.test words continuations sequences.private hashtables.private byte-arrays strings.private system random layouts vectors.private sbufs.private strings.private slots.private alien alien.accessors -alien.c-types alien.syntax namespaces libc combinators.private ; +alien.c-types alien.syntax namespaces libc sequences.private ; ! Make sure that intrinsic ops compile to correct code. [ ] [ 1 [ drop ] compile-call ] unit-test diff --git a/core/compiler/tests/simple.factor b/core/compiler/tests/simple.factor index 743fb713d9..1ed43120d3 100755 --- a/core/compiler/tests/simple.factor +++ b/core/compiler/tests/simple.factor @@ -1,5 +1,5 @@ USING: compiler tools.test kernel kernel.private -combinators.private math.private math combinators strings +sequences.private math.private math combinators strings alien arrays memory ; IN: temporary diff --git a/core/compiler/tests/templates.factor b/core/compiler/tests/templates.factor index 08e1c98729..74e5ab80a4 100755 --- a/core/compiler/tests/templates.factor +++ b/core/compiler/tests/templates.factor @@ -2,7 +2,7 @@ USING: arrays compiler kernel kernel.private math hashtables.private math.private namespaces sequences sequences.private tools.test namespaces.private slots.private -combinators.private byte-arrays alien alien.accessors layouts +sequences.private byte-arrays alien alien.accessors layouts words definitions compiler.units ; IN: temporary diff --git a/core/generic/math/math.factor b/core/generic/math/math.factor index 21a7857646..2cc28ac0d1 100755 --- a/core/generic/math/math.factor +++ b/core/generic/math/math.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays generic hashtables kernel kernel.private math namespaces sequences words quotations layouts combinators -combinators.private classes definitions ; +sequences.private classes definitions ; IN: generic.math PREDICATE: class math-class ( object -- ? ) diff --git a/core/generic/standard/standard.factor b/core/generic/standard/standard.factor index 7f4f423d8b..49b003bd62 100755 --- a/core/generic/standard/standard.factor +++ b/core/generic/standard/standard.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs kernel kernel.private slots.private math namespaces sequences vectors words quotations definitions -hashtables layouts combinators combinators.private generic +hashtables layouts combinators sequences.private generic classes classes.private ; IN: generic.standard diff --git a/core/inference/backend/backend-docs.factor b/core/inference/backend/backend-docs.factor index 98e2e6bbcd..1d742e144a 100755 --- a/core/inference/backend/backend-docs.factor +++ b/core/inference/backend/backend-docs.factor @@ -1,6 +1,6 @@ USING: help.syntax help.markup words effects inference.dataflow inference.state inference.backend kernel sequences -kernel.private combinators combinators.private ; +kernel.private combinators sequences.private ; HELP: literal-expected { $error-description "Thrown when inference encounters a " { $link call } " or " { $link if } " being applied to a value which is not known to be a literal. Such a form can have an arbitrary stack effect, and does not compile." } diff --git a/core/inference/inference-tests.factor b/core/inference/inference-tests.factor index 7a4176abfb..b841080c94 100755 --- a/core/inference/inference-tests.factor +++ b/core/inference/inference-tests.factor @@ -5,7 +5,7 @@ sequences strings vectors words quotations effects tools.test continuations generic.standard sorting assocs definitions prettyprint io inspector tuples classes.union classes.predicate debugger threads.private io.streams.string io.timeouts -combinators.private ; +sequences.private ; IN: temporary { 0 2 } [ 2 "Hello" ] must-infer-as diff --git a/core/inference/known-words/known-words.factor b/core/inference/known-words/known-words.factor index 69e331a9bf..a1887e206b 100755 --- a/core/inference/known-words/known-words.factor +++ b/core/inference/known-words/known-words.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.accessors arrays bit-arrays byte-arrays -classes combinators.private continuations.private effects +classes sequences.private continuations.private effects float-arrays generic hashtables hashtables.private inference.state inference.backend inference.dataflow io io.backend io.files io.files.private io.streams.c kernel diff --git a/core/kernel/kernel.factor b/core/kernel/kernel.factor index 7c4930f5a8..8d639aff78 100755 --- a/core/kernel/kernel.factor +++ b/core/kernel/kernel.factor @@ -17,6 +17,7 @@ IN: kernel : clear ( -- ) { } set-datastack ; ! Combinators + : call ( callable -- ) uncurry (call) ; DEFER: if diff --git a/core/optimizer/known-words/known-words.factor b/core/optimizer/known-words/known-words.factor index 43c0324611..3dce9d8f82 100755 --- a/core/optimizer/known-words/known-words.factor +++ b/core/optimizer/known-words/known-words.factor @@ -8,7 +8,7 @@ assocs quotations sequences.private io.binary io.crc32 io.streams.string layouts splitting math.intervals math.floats.private tuples tuples.private classes optimizer.def-use optimizer.backend optimizer.pattern-match -float-arrays combinators.private combinators ; +float-arrays sequences.private combinators ; ! the output of and has the class which is ! its second-to-last input diff --git a/core/optimizer/specializers/specializers.factor b/core/optimizer/specializers/specializers.factor index 223ce18117..af8cd5b82e 100755 --- a/core/optimizer/specializers/specializers.factor +++ b/core/optimizer/specializers/specializers.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays generic hashtables kernel kernel.private math namespaces sequences vectors words strings layouts combinators -combinators.private classes generic.standard assocs ; +sequences.private classes generic.standard assocs ; IN: optimizer.specializers : (make-specializer) ( class picker -- quot ) diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 5bb09d68dc..967fcbbdc8 100755 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2005, 2007 Slava Pestov. +! Copyright (C) 2005, 2008 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. IN: sequences USING: kernel kernel.private slots.private math math.private ; @@ -77,6 +77,8 @@ PREDICATE: fixnum array-capacity : set-array-nth ( elt n array -- ) swap 2 fixnum+fast set-slot ; inline +: dispatch ( n array -- ) array-nth (call) ; + GENERIC: resize ( n seq -- newseq ) flushable ! Unsafe sequence protocol for inner loops @@ -614,13 +616,21 @@ M: sequence <=> dup midpoint@ cut-slice ; : binary-reduce ( seq start quot -- value ) - pick length { - { 0 [ drop nip ] } - { 1 [ 2drop first ] } - { 2 [ >r drop first2 r> call ] } - { 3 [ >r drop first3 r> 2apply ] } - [ drop >r >r halves r> r> [ [ split-reduce ] 2curry 2apply ] keep call ] - } case ; inline + #! We can't use case here since combinators depends on + #! sequences + pick length dup 0 3 between? [ + >fixnum { + [ drop nip ] + [ 2drop first ] + [ >r drop first2 r> call ] + [ >r drop first3 r> 2apply ] + } dispatch + ] [ + drop + >r >r halves r> r> + [ [ binary-reduce ] 2curry 2apply ] keep + call + ] if ; inline : cut ( seq n -- before after ) [ head ] 2keep tail ; diff --git a/core/vocabs/loader/loader-docs.factor b/core/vocabs/loader/loader-docs.factor index 379b300eaa..a306efbd68 100755 --- a/core/vocabs/loader/loader-docs.factor +++ b/core/vocabs/loader/loader-docs.factor @@ -42,23 +42,9 @@ HELP: vocab-main HELP: vocab-roots { $var-description "A sequence of pathname strings to search for vocabularies." } ; -HELP: vocab-source -{ $values { "vocab" "a vocabulary specifier" } { "path" string } } -{ $description "Outputs a pathname relative to a vocabulary root where the source code for " { $snippet "vocab" } " might be found." } ; - -{ vocab-source vocab-source-path } related-words - -HELP: vocab-docs -{ $values { "vocab" "a vocabulary specifier" } { "path" string } } -{ $description "Outputs a pathname relative to a vocabulary root where the documentation for " { $snippet "vocab" } " might be found." } ; - -{ vocab-docs vocab-docs-path } related-words - HELP: vocab-tests -{ $values { "vocab" "a vocabulary specifier" } { "path" string } } -{ $description "Outputs a pathname relative to a vocabulary root where the unit tests for " { $snippet "vocab" } " might be found." } ; - -{ vocab-tests vocab-tests-path } related-words +{ $values { "vocab" "a vocabulary specifier" } { "tests" "a sequence of pathname strings" } } +{ $description "Outputs a sequence of pathnames where the unit tests for " { $snippet "vocab" } " are located." } ; HELP: find-vocab-root { $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string" } } @@ -86,14 +72,6 @@ HELP: load-docs { $values { "root" "a pathname string" } { "name" "a vocabulary name" } } { $description "If " { $link load-help? } " is on, loads a vocabulary's documentation from the specified vocabulary root." } ; -HELP: amend-vocab-from-root -{ $values { "root" "a pathname string" } { "name" "a vocabulary name" } { "vocab" vocab } } -{ $description "Loads a vocabulary's source code and documentation if they have not already been loaded, and outputs the vocabulary." } ; - -HELP: load-vocab-from-root -{ $values { "root" "a pathname string" } { "name" "a vocabulary name" } } -{ $description "Loads a vocabulary's source code and documentation." } ; - HELP: reload { $values { "name" "a vocabulary name" } } { $description "Loads it's source code and documentation." } @@ -116,10 +94,6 @@ HELP: vocab-docs-path { $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string or " { $link f } } } { $description "Outputs a pathname where the documentation for " { $snippet "vocab" } " might be found. Outputs " { $link f } " if the vocabulary does not have a directory on disk." } ; -HELP: vocab-tests-path -{ $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string or " { $link f } } } -{ $description "Outputs a pathname where the unit tests for " { $snippet "vocab" } " might be found. Outputs " { $link f } " if the vocabulary does not have a directory on disk." } ; - HELP: refresh { $values { "prefix" string } } { $description "Reloads source files and documentation belonging to loaded vocabularies whose names are prefixed by " { $snippet "prefix" } " which have been modified on disk." } ; diff --git a/extra/benchmark/dispatch4/dispatch4.factor b/extra/benchmark/dispatch4/dispatch4.factor old mode 100644 new mode 100755 index a5bb983151..a92772a923 --- a/extra/benchmark/dispatch4/dispatch4.factor +++ b/extra/benchmark/dispatch4/dispatch4.factor @@ -1,5 +1,5 @@ USING: kernel.private kernel sequences math combinators -combinators.private ; +sequences.private ; IN: benchmark.dispatch4 : foobar-1 diff --git a/extra/combinators/lib/lib-docs.factor b/extra/combinators/lib/lib-docs.factor index 02c3556742..d850243bd0 100755 --- a/extra/combinators/lib/lib-docs.factor +++ b/extra/combinators/lib/lib-docs.factor @@ -47,42 +47,6 @@ HELP: nkeep } { $see-also keep nslip } ; -HELP: map-withn -{ $values { "seq" sequence } { "quot" quotation } { "n" number } { "newseq" sequence } } -{ $description "A generalisation of " { $link map } ". The first " { $snippet "n" } " items after the quotation will be " -"passed to the quotation given to map-withn for each element in the sequence." -} -{ $examples - { $example "USE: combinators.lib" "1 2 3 4 { 6 7 8 9 10 } [ + + + + ] 4 map-withn .s" "{ 16 17 18 19 20 }" } -} -{ $see-also each-withn } ; - -HELP: each-withn -{ $values { "seq" sequence } { "quot" quotation } { "n" number } } -{ $description "A generalisation of " { $link each } ". The first " { $snippet "n" } " items after the quotation will be " -"passed to the quotation given to each-withn for each element in the sequence." -} -{ $see-also map-withn } ; - -HELP: sigma -{ $values { "seq" sequence } { "quot" quotation } { "n" number } } -{ $description "Like map sum, but without creating an intermediate sequence." } -{ $example - "! Find the sum of the squares [0,99]" - "USING: math.ranges combinators.lib ;" - "100 [1,b] [ sq ] sigma ." - "338350" -} ; - -HELP: count -{ $values { "seq" sequence } { "quot" quotation } { "n" integer } } -{ $description "Efficiently returns the number of elements that the predicate quotation matches." } -{ $example - "USING: math.ranges combinators.lib ;" - "100 [1,b] [ even? ] count ." - "50" -} ; - HELP: && { $values { "quots" "a sequence of quotations with stack effect " { $snippet "( ... -- ... ? )" } } { "?" "a boolean" } } { $description "Calls each quotation in turn; outputs " { $link f } " if one of the quotations output " { $link f } ", otherwise outputs " { $link t } ". As soon as a quotation outputs " { $link f } ", evaluation stops and subsequent quotations are not called." } ; diff --git a/extra/cpu/8080/emulator/emulator.factor b/extra/cpu/8080/emulator/emulator.factor old mode 100644 new mode 100755 index 0eca7bdc47..310e387bd5 --- a/extra/cpu/8080/emulator/emulator.factor +++ b/extra/cpu/8080/emulator/emulator.factor @@ -4,7 +4,7 @@ USING: kernel math sequences words arrays io io.files namespaces math.parser kernel.private assocs quotations parser parser-combinators tools.time - combinators.private compiler.units ; + sequences.private compiler.units ; IN: cpu.8080.emulator TUPLE: cpu b c d e f h l a pc sp halted? last-interrupt cycles ram ; diff --git a/extra/icfp/2006/2006.factor b/extra/icfp/2006/2006.factor old mode 100644 new mode 100755 index 53c7fd5a9b..2a35ed08f8 --- a/extra/icfp/2006/2006.factor +++ b/extra/icfp/2006/2006.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Gavin Harrison ! See http://factorcode.org/license.txt for BSD license. USING: kernel math sequences kernel.private namespaces arrays io io.files - splitting io.binary math.functions vectors quotations combinators.private ; + splitting io.binary math.functions vectors quotations sequences.private ; IN: icfp.2006 SYMBOL: regs diff --git a/extra/inverse/inverse.factor b/extra/inverse/inverse.factor old mode 100644 new mode 100755 index b97748514c..99dddb25f0 --- a/extra/inverse/inverse.factor +++ b/extra/inverse/inverse.factor @@ -1,7 +1,7 @@ USING: kernel words inspector slots quotations sequences assocs math arrays inference effects shuffle continuations debugger tuples namespaces vectors bit-arrays byte-arrays strings sbufs -math.functions macros combinators.private combinators ; +math.functions macros sequences.private combinators ; IN: inverse TUPLE: fail ; diff --git a/extra/optimizer/debugger/debugger.factor b/extra/optimizer/debugger/debugger.factor index 900f5a3829..499222073b 100755 --- a/extra/optimizer/debugger/debugger.factor +++ b/extra/optimizer/debugger/debugger.factor @@ -3,7 +3,7 @@ USING: classes inference inference.dataflow io kernel kernel.private math.parser namespaces optimizer prettyprint prettyprint.backend sequences words arrays match macros -assocs combinators.private ; +assocs sequences.private ; IN: optimizer.debugger ! A simple tool for turning dataflow IR into quotations, for diff --git a/extra/sequences/lib/lib-docs.factor b/extra/sequences/lib/lib-docs.factor new file mode 100755 index 0000000000..eb56e35cd5 --- /dev/null +++ b/extra/sequences/lib/lib-docs.factor @@ -0,0 +1,39 @@ +USING: help.syntax help.markup kernel prettyprint sequences +quotations math ; +IN: sequences.lib + +HELP: map-withn +{ $values { "seq" sequence } { "quot" quotation } { "n" number } { "newseq" sequence } } +{ $description "A generalisation of " { $link map } ". The first " { $snippet "n" } " items after the quotation will be " +"passed to the quotation given to map-withn for each element in the sequence." +} +{ $examples + { $example "USE: combinators.lib" "1 2 3 4 { 6 7 8 9 10 } [ + + + + ] 4 map-withn .s" "{ 16 17 18 19 20 }" } +} +{ $see-also each-withn } ; + +HELP: each-withn +{ $values { "seq" sequence } { "quot" quotation } { "n" number } } +{ $description "A generalisation of " { $link each } ". The first " { $snippet "n" } " items after the quotation will be " +"passed to the quotation given to each-withn for each element in the sequence." +} +{ $see-also map-withn } ; + +HELP: sigma +{ $values { "seq" sequence } { "quot" quotation } { "n" number } } +{ $description "Like map sum, but without creating an intermediate sequence." } +{ $example + "! Find the sum of the squares [0,99]" + "USING: math.ranges combinators.lib ;" + "100 [1,b] [ sq ] sigma ." + "338350" +} ; + +HELP: count +{ $values { "seq" sequence } { "quot" quotation } { "n" integer } } +{ $description "Efficiently returns the number of elements that the predicate quotation matches." } +{ $example + "USING: math.ranges combinators.lib ;" + "100 [1,b] [ even? ] count ." + "50" +} ; diff --git a/extra/sequences/lib/lib.factor b/extra/sequences/lib/lib.factor index f7ac9c340d..048d63dc64 100755 --- a/extra/sequences/lib/lib.factor +++ b/extra/sequences/lib/lib.factor @@ -3,7 +3,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: combinators.lib kernel sequences math namespaces assocs random sequences.private shuffle math.functions mirrors -arrays math.parser sorting strings ascii ; +arrays math.parser sorting strings ascii macros ; IN: sequences.lib : each-withn ( seq quot n -- ) nwith each ; inline diff --git a/extra/space-invaders/space-invaders.factor b/extra/space-invaders/space-invaders.factor index 4d74968c35..f5c518865d 100755 --- a/extra/space-invaders/space-invaders.factor +++ b/extra/space-invaders/space-invaders.factor @@ -5,7 +5,7 @@ USING: cpu.8080 cpu.8080.emulator openal math alien.c-types sequences kernel shuffle arrays io.files combinators kernel.private ui.gestures ui.gadgets ui.render opengl.gl system threads concurrency match ui byte-arrays combinators.lib - combinators.private ; + sequences.private ; IN: space-invaders TUPLE: space-invaders port1 port2i port2o port3o port4lo port4hi port5o bitmap sounds looping? ; diff --git a/extra/state-machine/state-machine.factor b/extra/state-machine/state-machine.factor old mode 100644 new mode 100755 index ac0bdc81c7..cd3cfc6324 --- a/extra/state-machine/state-machine.factor +++ b/extra/state-machine/state-machine.factor @@ -1,5 +1,5 @@ USING: kernel parser strings math namespaces sequences words io -arrays quotations debugger kernel.private combinators.private ; +arrays quotations debugger kernel.private sequences.private ; IN: state-machine : STATES: diff --git a/extra/tools/interpreter/interpreter.factor b/extra/tools/interpreter/interpreter.factor index f438bcd8df..f05b3a833f 100755 --- a/extra/tools/interpreter/interpreter.factor +++ b/extra/tools/interpreter/interpreter.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2004, 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays assocs classes combinators combinators.private +USING: arrays assocs classes combinators sequences.private continuations continuations.private generic hashtables io kernel kernel.private math namespaces namespaces.private prettyprint quotations sequences splitting strings threads vectors words ;