]> gitweb.factorcode.org Git - factor.git/commitdiff
Move remaining sequence operations from generalizations to sequences.generalizations...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 18 May 2010 22:36:47 +0000 (18:36 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 18 May 2010 22:36:47 +0000 (18:36 -0400)
39 files changed:
basis/alien/fortran/fortran.factor
basis/bootstrap/image/image.factor
basis/checksums/sha/sha.factor
basis/combinators/smart/smart.factor
basis/compiler/cfg/def-use/def-use.factor
basis/compiler/cfg/intrinsics/simd/backend/backend.factor
basis/compiler/cfg/representations/preferred/preferred.factor
basis/compiler/codegen/fixup/fixup.factor
basis/compiler/tree/propagation/transforms/transforms.factor
basis/generalizations/generalizations-docs.factor
basis/generalizations/generalizations-tests.factor
basis/generalizations/generalizations.factor
basis/inverse/inverse.factor
basis/locals/rewrite/sugar/sugar.factor
basis/logging/logging.factor
basis/math/vectors/simd/intrinsics/intrinsics.factor
basis/math/vectors/simd/simd.factor
basis/models/arrow/smart/smart.factor
basis/models/range/range.factor
basis/nmake/nmake.factor
basis/opengl/opengl.factor
basis/sequences/generalizations/generalizations-docs.factor
basis/sequences/generalizations/generalizations-tests.factor
basis/sequences/generalizations/generalizations.factor
basis/shuffle/shuffle.factor
basis/tools/annotations/annotations.factor
basis/tools/memory/memory.factor
basis/tools/test/test.factor
basis/unix/unix.factor
basis/xml/syntax/inverse/inverse.factor
basis/xml/syntax/syntax.factor
extra/audio/engine/engine.factor
extra/c/lexer/lexer.factor
extra/constructors/constructors.factor
extra/db/info/info.factor [deleted file]
extra/descriptive/descriptive.factor
extra/math/matrices/simd/simd.factor
extra/multi-methods/multi-methods.factor
extra/smalltalk/compiler/compiler.factor

index 27bd183a2e848f9341849744db7203949a8b526f..3d874310841dc3b81dc59b6ca5b8b6d9e46848e9 100755 (executable)
@@ -1,11 +1,12 @@
 ! (c) 2009 Joe Groff, see BSD license
-USING: accessors alien alien.c-types alien.complex alien.data alien.parser
-grouping alien.strings alien.syntax arrays ascii assocs
-byte-arrays combinators combinators.short-circuit fry generalizations
-kernel lexer macros math math.parser namespaces parser sequences
-splitting stack-checker vectors vocabs.parser words locals
-io.encodings.ascii io.encodings.string shuffle effects math.ranges
-math.order sorting strings system alien.libraries ;
+USING: accessors alien alien.c-types alien.complex alien.data
+alien.parser grouping alien.strings alien.syntax arrays ascii
+assocs byte-arrays combinators combinators.short-circuit fry
+generalizations kernel lexer macros math math.parser namespaces
+parser sequences sequences.generalizations splitting
+stack-checker vectors vocabs.parser words locals
+io.encodings.ascii io.encodings.string shuffle effects
+math.ranges math.order sorting strings system alien.libraries ;
 QUALIFIED-WITH: alien.c-types c
 IN: alien.fortran
 
index 62240f73ce1f044183db3af5f84f7933a5156c0c..68fbf55105c3530ec648cf3b275c893ce255cdb2 100644 (file)
@@ -3,11 +3,11 @@
 USING: alien alien.strings arrays byte-arrays generic hashtables
 hashtables.private io io.binary io.files io.encodings.binary
 io.pathnames kernel kernel.private math namespaces make parser
-prettyprint sequences strings sbufs vectors words quotations
-assocs system layouts splitting grouping growable classes
-classes.private classes.builtin classes.tuple
-classes.tuple.private vocabs vocabs.loader source-files
-definitions debugger quotations.private combinators
+prettyprint sequences sequences.generalizations strings sbufs
+vectors words quotations assocs system layouts splitting
+grouping growable classes classes.private classes.builtin
+classes.tuple classes.tuple.private vocabs vocabs.loader
+source-files definitions debugger quotations.private combinators
 combinators.short-circuit math.order math.private accessors
 slots.private generic.single.private compiler.units
 compiler.constants fry locals bootstrap.image.syntax
index af0f95fa76a71d5f5c72eadf646f992b23b1e655..82d2c2b4919606e33739a5e274842e295868b15f 100644 (file)
@@ -4,7 +4,7 @@ USING: accessors checksums checksums.common checksums.stream
 combinators combinators.smart fry generalizations grouping
 io.binary kernel literals locals make math math.bitwise
 math.ranges multiline namespaces sbufs sequences
-sequences.private splitting strings ;
+sequences.generalizations sequences.private splitting strings ;
 IN: checksums.sha
 
 SINGLETON: sha1
index a907d2d29754fc492c0a9fded5bd0b3250d97fce..c0ce938abb20e9dc49e3b271a805da2a5a84ec67 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors fry generalizations kernel macros math.order
-stack-checker math sequences ;
+USING: accessors fry generalizations sequences.generalizations
+kernel macros math.order stack-checker math sequences ;
 IN: combinators.smart
 
 MACRO: drop-outputs ( quot -- quot' )
index 93c1a53b44b9aaf3a0e8845865d541ebfb0578b7..a2a0b2d8be41bbd2b1e0c9cffccf80dc42a55ec3 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs arrays classes combinators
-compiler.units fry generalizations generic kernel locals
-namespaces quotations sequences sets slots words
-compiler.cfg.instructions compiler.cfg.instructions.syntax
+compiler.units fry generalizations sequences.generalizations
+generic kernel locals namespaces quotations sequences sets slots
+words compiler.cfg.instructions compiler.cfg.instructions.syntax
 compiler.cfg.rpo ;
 FROM: namespaces => set ;
 FROM: sets => members ;
index f84e826f19ffb86ddcbeb69bc8ed7a46e70d25e4..bc1e04a2f325ef5112a0bae5b23b32f4fbb34288 100644 (file)
@@ -6,7 +6,7 @@ compiler.cfg.stacks.local compiler.tree.propagation.info
 compiler.cfg.instructions
 cpu.architecture effects fry generalizations
 kernel locals macros make math namespaces quotations sequences
-splitting stack-checker words ;
+sequences.generalizations splitting stack-checker words ;
 IN: compiler.cfg.intrinsics.simd.backend
 
 ! Selection of implementation based on available CPU instructions
index e1a9ec0d939160575c248575d794f68f93f2c1dc..8ca91c4389069cd5453beb49cdcfc1782efd7ced 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors sequences arrays fry namespaces generic
-words sets combinators generalizations cpu.architecture compiler.units
-compiler.cfg.utilities compiler.cfg compiler.cfg.rpo
-compiler.cfg.instructions compiler.cfg.def-use ;
+words sets combinators generalizations sequences.generalizations
+cpu.architecture compiler.units compiler.cfg.utilities
+compiler.cfg compiler.cfg.rpo compiler.cfg.instructions
+compiler.cfg.def-use ;
 FROM: compiler.cfg.instructions.syntax => insn-def-slot insn-use-slots insn-temp-slots scalar-rep ;
 FROM: namespaces => set ;
 IN: compiler.cfg.representations.preferred
index 518efc8055e3d54f852615f8fe81f61555a3c6d2..9e366cd40833c0f8cd220da8c0d58f820e79d9dd 100644 (file)
@@ -3,7 +3,7 @@
 USING: arrays byte-arrays byte-vectors generic assocs hashtables
 io.binary kernel kernel.private math namespaces make sequences
 words quotations strings alien.accessors alien.strings layouts
-system combinators math.bitwise math.order generalizations
+system combinators math.bitwise math.order combinators.smart
 accessors growable fry compiler.constants memoize ;
 IN: compiler.codegen.fixup
 
@@ -138,12 +138,14 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
 
 : with-fixup ( quot -- code )
     '[
-        init-fixup
-        @
-        emit-binary-literals
-        label-table [ compute-labels ] change
-        parameter-table get >array
-        literal-table get >array
-        relocation-table get >byte-array
-        label-table get
-    ] B{ } make 5 narray ; inline
+        [
+            init-fixup
+            @
+            emit-binary-literals
+            label-table [ compute-labels ] change
+            parameter-table get >array
+            literal-table get >array
+            relocation-table get >byte-array
+            label-table get
+        ] B{ } make
+    ] output>array ; inline
index 3d2d7ac298c17d42ed59abac16b300aec34b15c7..a89238dc5cdd1bf97482903f7ae43d82968d960a 100644 (file)
@@ -6,9 +6,10 @@ definitions stack-checker.dependencies quotations
 classes.tuple.private math math.partial-dispatch math.private
 math.intervals sets.private math.floats.private
 math.integers.private layouts math.order vectors hashtables
-combinators effects generalizations assocs sets
-combinators.short-circuit sequences.private locals growable
-stack-checker namespaces compiler.tree.propagation.info ;
+combinators effects generalizations sequences.generalizations
+assocs sets combinators.short-circuit sequences.private locals
+growable stack-checker namespaces compiler.tree.propagation.info
+;
 FROM: math => float ;
 FROM: sets => set ;
 IN: compiler.tree.propagation.transforms
index d21b2b022c1fa2e4da22264e67c6cf16ac11ad6a..168f2dfcd2e8762ab7874eaff358051958de4b5d 100644 (file)
@@ -2,59 +2,10 @@ USING: help.syntax help.markup kernel sequences quotations
 math arrays combinators ;\r
 IN: generalizations\r
 \r
-HELP: nsequence\r
-{ $values { "n" integer } { "seq" "an exemplar" } }\r
-{ $description "A generalization of " { $link 2sequence } ", "\r
-{ $link 3sequence } ", and " { $link 4sequence } " "\r
-"that constructs a sequence from the top " { $snippet "n" } " elements of the stack."\r
-}\r
-{ $examples\r
-    { $example "USING: generalizations prettyprint ;" "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }\r
-} ;\r
-\r
-HELP: narray\r
-{ $values { "n" integer } }\r
-{ $description "A generalization of " { $link 1array } ", "\r
-{ $link 2array } ", " { $link 3array } " and " { $link 4array } " "\r
-"that constructs an array from the top " { $snippet "n" } " elements of the stack."\r
-}\r
-{ $examples\r
-    "Some core words expressed in terms of " { $link narray } ":"\r
-    { $table\r
-        { { $link 1array } { $snippet "1 narray" } }\r
-        { { $link 2array } { $snippet "2 narray" } }\r
-        { { $link 3array } { $snippet "3 narray" } }\r
-        { { $link 4array } { $snippet "4 narray" } }\r
-    }\r
-} ;\r
-\r
-{ nsequence narray } related-words\r
-\r
 HELP: nsum\r
 { $values { "n" integer } }\r
 { $description "Adds the top " { $snippet "n" } " stack values." } ;\r
 \r
-HELP: firstn\r
-{ $values { "n" integer } }\r
-{ $description "A generalization of " { $link first } ", "\r
-{ $link first2 } ", " { $link first3 } " and " { $link first4 } " "\r
-"that pushes the first " { $snippet "n" } " elements of a sequence on the stack."\r
-}\r
-{ $examples\r
-    "Some core words expressed in terms of " { $link firstn } ":"\r
-    { $table\r
-        { { $link first } { $snippet "1 firstn" } }\r
-        { { $link first2 } { $snippet "2 firstn" } }\r
-        { { $link first3 } { $snippet "3 firstn" } }\r
-        { { $link first4 } { $snippet "4 firstn" } }\r
-    }\r
-} ;\r
-\r
-HELP: set-firstn\r
-{ $values { "n" integer } }\r
-{ $description "A generalization of " { $link set-first } " "\r
-"that sets the first " { $snippet "n" } " elements of a sequence from the top " { $snippet "n" } " elements of the stack." } ;\r
-\r
 HELP: npick\r
 { $values { "n" integer } }\r
 { $description "A generalization of " { $link dup } ", "\r
@@ -302,46 +253,6 @@ HELP: n*quot
 }\r
 { $description "Construct a quotation containing the contents of " { $snippet "seq" } " repeated " { $snippet "n"} " times." } ;\r
 \r
-HELP: nappend\r
-{ $values\r
-     { "n" integer }\r
-     { "seq" sequence }\r
-}\r
-{ $description "Outputs a new sequence consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }\r
-{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }\r
-{ $examples\r
-    { $example "USING: generalizations prettyprint math ;"\r
-               "{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 nappend ."\r
-               "{ 1 2 3 4 5 6 7 8 }"\r
-    }\r
-} ;\r
-\r
-HELP: nappend-as\r
-{ $values\r
-     { "n" integer } { "exemplar" sequence }\r
-     { "seq" sequence }\r
-}\r
-{ $description "Outputs a new sequence of type " { $snippet "exemplar" } " consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }\r
-{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }\r
-{ $examples\r
-    { $example "USING: generalizations prettyprint math ;"\r
-               "{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 V{ } nappend-as ."\r
-               "V{ 1 2 3 4 5 6 7 8 }"\r
-    }\r
-} ;\r
-\r
-{ nappend nappend-as } related-words\r
-\r
-ARTICLE: "sequence-generalizations" "Generalized sequence operations"\r
-{ $subsections\r
-    narray\r
-    nsequence\r
-    firstn\r
-    set-firstn\r
-    nappend\r
-    nappend-as\r
-} ;\r
-\r
 ARTICLE: "shuffle-generalizations" "Generalized shuffle words"\r
 { $subsections\r
     ndup\r
@@ -381,11 +292,10 @@ ARTICLE: "generalizations" "Generalized shuffle words and combinators"
 "macros where the arity of the input quotations depends on an "\r
 "input parameter."\r
 { $subsections\r
-    "sequence-generalizations"\r
     "shuffle-generalizations"\r
     "combinator-generalizations"\r
     "other-generalizations"\r
 }\r
-"Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence iteration combinators." ;\r
+"Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence operations." ;\r
 \r
 ABOUT: "generalizations"\r
index 477be4a20fd027c7b16330fd7cdbb44f86e4eb38..9b6374ca5f7c1f105bf35b006e638d8d14597bd5 100644 (file)
@@ -39,24 +39,10 @@ IN: generalizations.tests
 \r
 [ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test\r
 \r
-[ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test\r
-[ { 1 2 3 4 } ] [ 1 2 3 4 { f f f f } [ 4 set-firstn ] keep ] unit-test\r
-[ 1 2 3 4 { f f f } [ 4 set-firstn ] keep ] must-fail\r
-[ ] [ { } 0 firstn ] unit-test\r
-[ "a" ] [ { "a" } 1 firstn ] unit-test\r
-\r
-[ [ 1 2 ] ] [ 1 2 2 [ ] nsequence ] unit-test\r
-\r
 [ 4 5 1 2 3 ] [ 1 2 3 4 5 2 3 mnswap ] unit-test\r
 \r
 [ 1 2 3 4 5 6 ] [ 1 2 3 4 5 6 2 4 mnswap 4 2 mnswap ] unit-test\r
 \r
-[ { 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 nappend ] unit-test\r
-[ V{ 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 V{ } nappend-as ] unit-test\r
-\r
-[ 4 nappend ] must-infer\r
-[ 4 { } nappend-as ] must-infer\r
-\r
 [ 17 ] [ 3 1 3 3 7 5 nsum ] unit-test\r
 { 4 1 } [ 4 nsum ] must-infer-as\r
 \r
index ac5ff3dee073345f4983e180758dbb12e52e5909..2c6a9f1a21854e955b6f26d4b60c5da0d17b979c 100644 (file)
@@ -14,26 +14,9 @@ ALIAS: n*quot (n*quot)
 
 >>
 
-MACRO: nsequence ( n seq -- )
-    [ [nsequence] ] keep
-    '[ @ _ like ] ;
-
-MACRO: narray ( n -- )
-    '[ _ { } nsequence ] ;
-
 MACRO: nsum ( n -- )
     1 - [ + ] n*quot ;
 
-MACRO: firstn-unsafe ( n -- )
-    [firstn] ;
-
-MACRO: firstn ( n -- )
-    dup zero? [ drop [ drop ] ] [
-        [ 1 - swap bounds-check 2drop ]
-        [ firstn-unsafe ]
-        bi-curry '[ _ _ bi ]
-    ] if ;
-
 MACRO: npick ( n -- )
     1 - [ dup ] [ '[ _ dip swap ] ] repeat ;
 
@@ -53,18 +36,6 @@ MACRO: nrot ( n -- )
 MACRO: -nrot ( n -- )
     1 - [ ] [ '[ swap _ dip ] ] repeat ;
 
-MACRO: set-firstn-unsafe ( n -- )
-    [ 1 + ]
-    [ iota [ '[ _ rot [ set-nth-unsafe ] keep ] ] map ] bi
-    '[ _ -nrot _ spread drop ] ;
-
-MACRO: set-firstn ( n -- )
-    dup zero? [ drop [ drop ] ] [
-        [ 1 - swap bounds-check 2drop ]
-        [ set-firstn-unsafe ]
-        bi-curry '[ _ _ bi ]
-    ] if ;
-
 MACRO: ndrop ( n -- )
     [ drop ] n*quot ;
 
@@ -143,9 +114,3 @@ MACRO: nweave ( n -- )
 
 MACRO: nbi-curry ( n -- )
     [ bi-curry ] n*quot ;
-
-: nappend-as ( n exemplar -- seq )
-    [ narray concat ] dip like ; inline
-
-: nappend ( n -- seq ) narray concat ; inline
-
index 3485b3efa709c75927485470ce37f66842fb6f0c..b4a3b72b3c8d89232f4b1001ca016b4092e69d8c 100644 (file)
@@ -6,7 +6,7 @@ classes.tuple namespaces make vectors bit-arrays byte-arrays
 strings sbufs math.functions macros sequences.private
 combinators mirrors splitting combinators.smart
 combinators.short-circuit fry words.symbol generalizations
-classes ;
+sequences.generalizations classes ;
 IN: inverse
 
 ERROR: fail ;
index 9dfc733fffc0380cbbc1ac89a1cbba81204e7890..110cc6ad81db7249dba9ccb2b2aacd274b2b456a 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs classes classes.tuple fry
-generalizations hashtables kernel locals locals.backend
+sequences.generalizations hashtables kernel locals locals.backend
 locals.errors locals.types make quotations sequences vectors
 words ;
 IN: locals.rewrite.sugar
index c8179108ef12d359c2958bd413c5b68c164b09ff..7542c269bdff9be2b5779b093645cdccabe71ef7 100644 (file)
@@ -4,7 +4,8 @@ USING: logging.server sequences namespaces concurrency.messaging
 words kernel arrays shuffle tools.annotations\r
 prettyprint.config prettyprint debugger io.streams.string\r
 splitting continuations effects generalizations parser strings\r
-quotations fry accessors math assocs math.order ;\r
+quotations fry accessors math assocs math.order\r
+sequences.generalizations ;\r
 IN: logging\r
 \r
 SYMBOLS: DEBUG NOTICE WARNING ERROR CRITICAL ;\r
index 021ffc5a0c2c7ab6f46faab4192bebc252222eb8..c7d650e1e6fe9c7171dc4b5c40f8d58439116847 100644 (file)
@@ -2,8 +2,8 @@
 USING: accessors alien alien.c-types alien.data combinators
 sequences.cords cpu.architecture fry generalizations grouping
 kernel libc locals math math.libm math.order math.ranges
-math.vectors sequences sequences.private specialized-arrays
-vocabs.loader ;
+math.vectors sequences sequences.generalizations
+sequences.private specialized-arrays vocabs.loader ;
 QUALIFIED-WITH: alien.c-types c
 SPECIALIZED-ARRAYS:
     c:char c:short c:int c:longlong
index 73a6faeee8768b50274d030e639833f731298c7e..708fcaa190d2c041bf1a1e7088923d494455d3d6 100644 (file)
@@ -3,7 +3,8 @@ cpu.architecture effects fry functors generalizations generic
 generic.parser kernel lexer literals locals macros math math.functions
 math.vectors math.vectors.private math.vectors.simd.intrinsics
 namespaces parser prettyprint.custom quotations sequences
-sequences.private vocabs vocabs.loader words ;
+sequences.generalizations sequences.private vocabs vocabs.loader
+words ;
 QUALIFIED-WITH: alien.c-types c
 IN: math.vectors.simd
 
index 7c29310a97716c9764422170e19e8f58cd37aac2..3398183edb3e6e4731208d0135869fb7c2c61e88 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: models.arrow models.product stack-checker accessors fry
-generalizations combinators.smart macros kernel ;
+generalizations sequences.generalizations combinators.smart
+macros kernel ;
 IN: models.arrow.smart
 
 MACRO: <smart-arrow> ( quot -- quot' )
index c39c80c7d15dc63de3e9cc70e01dca338e84c55a..9a4584a9a290bad9df5c5d0ddc4f25f776485d0c 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: accessors kernel models arrays sequences math math.order\r
-models.product generalizations math.functions ;\r
+models.product generalizations sequences.generalizations\r
+math.functions ;\r
 FROM: models.product => product ;\r
 IN: models.range\r
 \r
index 61a0950ce4a5d8523df2cd9d35de6ed8fa7419d4..912bb17218b9c5ee23f2cf2bde6f79719577ca6f 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces sequences math.parser kernel macros
-generalizations locals ;
+generalizations sequences.generalizations locals ;
 IN: nmake
 
 SYMBOL: building-seq 
index 1f6205e64fda4575661a31fa8b12096593611d24..6dcb4110a2687e3cea7bb11dd2c4d5b01a4b0762 100644 (file)
@@ -6,8 +6,8 @@ USING: alien alien.c-types ascii calendar combinators.short-circuit
 continuations kernel libc math macros namespaces math.vectors
 math.parser opengl.gl combinators combinators.smart arrays
 sequences splitting words byte-arrays assocs vocabs
-colors colors.constants accessors generalizations locals fry
-specialized-arrays ;
+colors colors.constants accessors generalizations
+sequences.generalizations locals fry specialized-arrays ;
 FROM: alien.c-types => float ;
 SPECIALIZED-ARRAY: float
 SPECIALIZED-ARRAY: uint
index 30ad1ea6280b2320d9c9512011858b1cf0378d9c..af1f67317044878a61d71543348337a41d9fa412 100644 (file)
@@ -3,6 +3,85 @@ USING: help.syntax help.markup kernel sequences quotations
 math arrays combinators ;
 IN: sequences.generalizations
 
+HELP: nsequence
+{ $values { "n" integer } { "seq" "an exemplar" } }
+{ $description "A generalization of " { $link 2sequence } ", "
+{ $link 3sequence } ", and " { $link 4sequence } " "
+"that constructs a sequence from the top " { $snippet "n" } " elements of the stack."
+}
+{ $examples
+    { $example "USING: generalizations prettyprint ;" "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }
+} ;
+
+HELP: narray
+{ $values { "n" integer } }
+{ $description "A generalization of " { $link 1array } ", "
+{ $link 2array } ", " { $link 3array } " and " { $link 4array } " "
+"that constructs an array from the top " { $snippet "n" } " elements of the stack."
+}
+{ $examples
+    "Some core words expressed in terms of " { $link narray } ":"
+    { $table
+        { { $link 1array } { $snippet "1 narray" } }
+        { { $link 2array } { $snippet "2 narray" } }
+        { { $link 3array } { $snippet "3 narray" } }
+        { { $link 4array } { $snippet "4 narray" } }
+    }
+} ;
+
+{ nsequence narray } related-words
+
+HELP: firstn
+{ $values { "n" integer } }
+{ $description "A generalization of " { $link first } ", "
+{ $link first2 } ", " { $link first3 } " and " { $link first4 } " "
+"that pushes the first " { $snippet "n" } " elements of a sequence on the stack."
+}
+{ $examples
+    "Some core words expressed in terms of " { $link firstn } ":"
+    { $table
+        { { $link first } { $snippet "1 firstn" } }
+        { { $link first2 } { $snippet "2 firstn" } }
+        { { $link first3 } { $snippet "3 firstn" } }
+        { { $link first4 } { $snippet "4 firstn" } }
+    }
+} ;
+
+HELP: set-firstn
+{ $values { "n" integer } }
+{ $description "A generalization of " { $link set-first } " "
+"that sets the first " { $snippet "n" } " elements of a sequence from the top " { $snippet "n" } " elements of the stack." } ;
+
+HELP: nappend
+{ $values
+     { "n" integer }
+     { "seq" sequence }
+}
+{ $description "Outputs a new sequence consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
+{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
+{ $examples
+    { $example "USING: generalizations prettyprint math ;"
+               "{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 nappend ."
+               "{ 1 2 3 4 5 6 7 8 }"
+    }
+} ;
+
+HELP: nappend-as
+{ $values
+     { "n" integer } { "exemplar" sequence }
+     { "seq" sequence }
+}
+{ $description "Outputs a new sequence of type " { $snippet "exemplar" } " consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
+{ $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
+{ $examples
+    { $example "USING: generalizations prettyprint math ;"
+               "{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 V{ } nappend-as ."
+               "V{ 1 2 3 4 5 6 7 8 }"
+    }
+} ;
+
+{ nappend nappend-as } related-words
+
 HELP: neach
 { $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( element... -- )" } } { "n" integer } }
 { $description "A generalization of " { $link each } ", " { $link 2each } ", and " { $link 3each } " that can iterate over any number of sequences in parallel." } ;
@@ -31,8 +110,17 @@ HELP: nproduce-as
 { $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "exemplar..." { $snippet "n" } " sequences on the datastack" } { "n" integer } { "seq..." { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
 { $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
 
-ARTICLE: "sequences.generalizations" "Generalized sequence iteration combinators"
-"The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of the iteration " { $link "sequences-combinators" } "."
+ARTICLE: "sequences.generalizations" "Generalized sequence words"
+"The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of various sequence operations."
+{ $subsections
+    narray
+    nsequence
+    firstn
+    set-firstn
+    nappend
+    nappend-as
+}
+"Generalized " { $link "sequences-combinators" } ":"
 { $subsections
     neach
     nmap
index d1861b8f9dcbc6cb931d94d8f47818f04a3183a4..ff2b7059300b510879be54c6996de5a719f91755 100644 (file)
@@ -3,6 +3,20 @@ USING: tools.test generalizations kernel math arrays sequences
 sequences.generalizations ascii fry math.parser io io.streams.string ;
 IN: sequences.generalizations.tests
 
+[ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test
+[ { 1 2 3 4 } ] [ 1 2 3 4 { f f f f } [ 4 set-firstn ] keep ] unit-test
+[ 1 2 3 4 { f f f } [ 4 set-firstn ] keep ] must-fail
+[ ] [ { } 0 firstn ] unit-test
+[ "a" ] [ { "a" } 1 firstn ] unit-test
+
+[ [ 1 2 ] ] [ 1 2 2 [ ] nsequence ] unit-test
+
+[ { 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 nappend ] unit-test
+[ V{ 1 2 3 4 } ] [ { 1 } { 2 } { 3 } { 4 } 4 V{ } nappend-as ] unit-test
+
+[ 4 nappend ] must-infer
+[ 4 { } nappend-as ] must-infer
+
 : neach-test ( a b c d -- )
     [ 4 nappend print ] 4 neach ;
 : nmap-test ( a b c d -- e )
index 60b1a8a0119898e7b2387332a84b8d87c0c5a0a5..8401930db398ce4d683e7b4923c0a949900a9dfb 100644 (file)
@@ -4,12 +4,47 @@ combinators macros math.order math.ranges quotations fry effects
 memoize.private generalizations ;
 IN: sequences.generalizations
 
+MACRO: nsequence ( n seq -- )
+    [ [nsequence] ] keep
+    '[ @ _ like ] ;
+
+MACRO: narray ( n -- )
+    '[ _ { } nsequence ] ;
+
+MACRO: firstn-unsafe ( n -- )
+    [firstn] ;
+
+MACRO: firstn ( n -- )
+    dup zero? [ drop [ drop ] ] [
+        [ 1 - swap bounds-check 2drop ]
+        [ firstn-unsafe ]
+        bi-curry '[ _ _ bi ]
+    ] if ;
+
+MACRO: set-firstn-unsafe ( n -- )
+    [ 1 + ]
+    [ iota [ '[ _ rot [ set-nth-unsafe ] keep ] ] map ] bi
+    '[ _ -nrot _ spread drop ] ;
+
+MACRO: set-firstn ( n -- )
+    dup zero? [ drop [ drop ] ] [
+        [ 1 - swap bounds-check 2drop ]
+        [ set-firstn-unsafe ]
+        bi-curry '[ _ _ bi ]
+    ] if ;
+
+: nappend-as ( n exemplar -- seq )
+    [ narray concat ] dip like ; inline
+
+: nappend ( n -- seq ) narray concat ; inline
+
 MACRO: nmin-length ( n -- )
     dup 1 - [ min ] n*quot
     '[ [ length ] _ napply @ ] ;
 
 : nnth-unsafe ( n seq... n -- )
     [ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline
+
 MACRO: nset-nth-unsafe ( n -- )
     [ [ drop ] ]
     [ '[ [ set-nth-unsafe ] _ [ apply-curry ] [ cleave-curry ] [ spread* ] tri ] ]
index b826606df51f85070e4d9ddb17270b3a1e9625a4..2659ed3280ddf9e7549a1e034cb3634b41237bfa 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2007 Chris Double, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs combinators effects.parser generalizations
-hashtables kernel locals locals.backend macros make math
-parser sequences ;
+USING: accessors assocs combinators effects.parser
+generalizations sequences.generalizations hashtables kernel
+locals locals.backend macros make math parser sequences ;
 IN: shuffle
 
 <PRIVATE
index c9dfc4a5625163b6586c5c45239e2eb89312f6ea..5c9210e44a6e39d0d8837a1c6903e0f73fb757b2 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2005, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel math sorting words parser io summary
-quotations sequences prettyprint continuations effects
-definitions compiler.units namespaces assocs tools.time generic
-inspector fry locals generalizations macros ;
+quotations sequences sequences.generalizations prettyprint
+continuations effects definitions compiler.units namespaces
+assocs tools.time generic inspector fry locals generalizations
+macros ;
 IN: tools.annotations
 
 <PRIVATE
index 1c999d979a58566a364ab031ea4adc4d2a1a54c4..1f1a9876b5d870c26e8c4e34da216185a0d7ffe8 100644 (file)
@@ -4,8 +4,9 @@ USING: accessors arrays assocs binary-search classes
 classes.struct combinators combinators.smart continuations fry
 generalizations generic grouping io io.styles kernel make math
 math.order math.parser math.statistics memory memory.private
-layouts namespaces parser prettyprint sequences sorting
-splitting strings system vm words hints hashtables ;
+layouts namespaces parser prettyprint sequences
+sequences.generalizations sorting splitting strings system vm
+words hints hashtables ;
 IN: tools.memory
 
 <PRIVATE
index 95f1ad8e2c086eca1b2e9ac7a722f356182506df..b789fa853785de6455618564f7b41885e73b2950 100644 (file)
@@ -1,13 +1,13 @@
 ! Copyright (C) 2003, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs combinators compiler.units
-continuations debugger effects fry generalizations io io.files
-io.styles kernel lexer locals macros math.parser namespaces
-parser vocabs.parser prettyprint quotations sequences
-source-files splitting stack-checker summary unicode.case
-vectors vocabs vocabs.loader vocabs.files vocabs.metadata words
-tools.errors source-files.errors io.streams.string make
-compiler.errors ;
+continuations debugger effects fry generalizations
+sequences.generalizations io io.files io.styles kernel lexer
+locals macros math.parser namespaces parser vocabs.parser
+prettyprint quotations sequences source-files splitting
+stack-checker summary unicode.case vectors vocabs vocabs.loader
+vocabs.files vocabs.metadata words tools.errors
+source-files.errors io.streams.string make compiler.errors ;
 IN: tools.test
 
 TUPLE: test-failure < source-file-error continuation ;
index d860bf490ea403edc6095d15dfc3c9acf5bfaba9..101736ea1f76681775989406def1f41ef4d500b4 100644 (file)
@@ -5,8 +5,8 @@ USING: accessors alien alien.c-types alien.libraries
 alien.syntax byte-arrays classes.struct combinators
 combinators.short-circuit combinators.smart continuations
 generalizations io kernel libc locals macros math namespaces
-sequences stack-checker strings system unix.time unix.types
-vocabs vocabs.loader unix.ffi ;
+sequences sequences.generalizations stack-checker strings system
+unix.time unix.types vocabs vocabs.loader unix.ffi ;
 IN: unix
 
 ERROR: unix-error errno message ;
index 002f60aa238c66508091257c71193522875dcafc..1d37a8dedbabc01383885a63f8fae8440724efad 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs combinators
 combinators.short-circuit fry generalizations inverse kernel
-namespaces sequences sorting strings unicode.categories
-xml.data xml.syntax xml.syntax.private ;
+namespaces sequences sequences.generalizations sorting strings
+unicode.categories xml.data xml.syntax xml.syntax.private ;
 IN: xml.syntax.inverse
 
 : remove-blanks ( seq -- newseq )
index e7e8714b294a050e6f7374b21eecac95c3bd2f65..92f3cd7a897733e5434ffb0e113991ac66f0cfe3 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2005, 2009 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: words assocs kernel accessors parser vocabs.parser effects.parser
-sequences summary lexer splitting combinators locals
-memoize sequences.deep xml.data xml.state xml namespaces present
-arrays generalizations strings make math macros multiline
-combinators.short-circuit sorting fry unicode.categories
-effects ;
+USING: words assocs kernel accessors parser vocabs.parser
+effects.parser sequences summary lexer splitting combinators
+locals memoize sequences.deep xml.data xml.state xml namespaces
+present arrays generalizations sequences.generalizations strings
+make math macros multiline combinators.short-circuit sorting fry
+unicode.categories effects ;
 IN: xml.syntax
 
 <PRIVATE
index ae94f5bb42f798f1383a7e2d43d99ebb69dfea43..02d53bd5ab77f6ca78b094e6c5533f9d10abaa46 100644 (file)
@@ -1,7 +1,8 @@
 ! (c)2009 Joe Groff bsd license
 USING: accessors alien audio classes.struct fry calendar alarms
 combinators combinators.short-circuit destructors generalizations
-kernel literals locals math openal sequences specialized-arrays strings ;
+kernel literals locals math openal sequences
+sequences.generalizations specialized-arrays strings ;
 QUALIFIED-WITH: alien.c-types c
 SPECIALIZED-ARRAYS: c:float c:uchar c:uint ;
 IN: audio.engine
index 9e613d54b44f6871f222e302a0e3999c612a7e73..a42c422bb8be58f5a8a20871d5cbe8cf00a564b1 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors combinators combinators.short-circuit
 generalizations kernel locals math.order math.ranges
-sequences.parser sequences sorting.functor sorting.slots
-unicode.categories ;
+sequences.parser sequences sequences.generalizations
+sorting.functor sorting.slots unicode.categories ;
 IN: c.lexer
 
 : take-c-comment ( sequence-parser -- seq/f )
index 51df4e8de6e360f1654d152c7b1928b618a9243c..6701e613249d2fec2f15b7eeb130cb4442c5cf7e 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2009 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs classes classes.tuple
-effects.parser fry generalizations generic.standard kernel
-lexer locals macros parser sequences sets slots vocabs words ;
+effects.parser fry generalizations sequences.generalizations
+generic.standard kernel lexer locals macros parser sequences
+sets slots vocabs words ;
 IN: constructors
 
 ! An experiment
diff --git a/extra/db/info/info.factor b/extra/db/info/info.factor
deleted file mode 100644 (file)
index 4d17b6b..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-USING: accessors sequences generalizations io.encodings.utf8 db.postgresql parser combinators vocabs.parser db.sqlite
-io.files ;
-IN: db.info
-! having sensative (and likely to change) information directly in source code seems a bad idea
-: get-info ( -- lines ) current-vocab name>> "vocab:" "/dbinfo.txt" surround utf8 file-lines ;
-SYNTAX: get-psql-info <postgresql-db> get-info 5 firstn
-    {
-        [ >>host ]
-        [ >>port ]
-        [ >>username ]
-        [ [ f ] [ ] if-empty >>password ]
-        [ >>database ]
-    } spread suffix! ;
-
-SYNTAX: get-sqlite-info get-info first <sqlite-db> suffix! ;
index 5c6b5028f8b51ad56546ccd8984f864e42dc9866..dec94d76bf854cc5223f9b627a30bc9d30910323 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (c) 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: words kernel sequences locals locals.parser fry
-locals.definitions accessors parser namespaces continuations
-summary definitions generalizations arrays prettyprint debugger io
-effects tools.annotations effects.parser ;
+USING: words kernel sequences sequences.generalizations locals
+locals.parser fry locals.definitions accessors parser namespaces
+continuations summary definitions generalizations arrays
+prettyprint debugger io effects tools.annotations effects.parser ;
 IN: descriptive
 
 ERROR: descriptive-error args underlying word ;
index 26ad8bb4d7549fb7eadf946bbe23284d5a48e63f..5ccd243a54737a444fd2aaab7b0db3f9665b3889 100644 (file)
@@ -1,7 +1,8 @@
 ! (c)Joe Groff bsd license
-USING: accessors classes.struct fry generalizations kernel locals
-math math.combinatorics math.functions math.matrices.simd math.vectors
-math.vectors.simd math.quaternions sequences sequences.private specialized-arrays
+USING: accessors classes.struct fry generalizations kernel
+locals math math.combinatorics math.functions math.matrices.simd
+math.vectors math.vectors.simd math.quaternions sequences
+sequences.generalizations sequences.private specialized-arrays
 typed ;
 FROM: sequences.private => nth-unsafe ;
 FROM: math.quaternions.private => (q*sign) ;
index a65e459a7c58c22f4644c66d00a3768d536e61e7..ebe60e00f63567afe405032e7d875ddc431353f8 100644 (file)
@@ -3,9 +3,9 @@
 USING: kernel math sequences vectors classes classes.algebra
 combinators arrays words assocs parser namespaces make
 definitions prettyprint prettyprint.backend prettyprint.custom
-quotations generalizations debugger io compiler.units
-kernel.private effects accessors hashtables sorting shuffle
-math.order sets see effects.parser ;
+quotations generalizations sequences.generalizations debugger io
+compiler.units kernel.private effects accessors hashtables
+sorting shuffle math.order sets see effects.parser ;
 FROM: namespaces => set ;
 IN: multi-methods
 
index 0c1a5c07d17d21e0073ddfb824ea2a84b309966b..fcb76c413503b9de83f6af47a9d3831ae5b8afc9 100644 (file)
@@ -2,10 +2,11 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs combinators.short-circuit
 continuations fry kernel namespaces quotations sequences sets
-generalizations slots locals.types splitting math
-locals.rewrite.closures generic words combinators locals smalltalk.ast
-smalltalk.compiler.lexenv smalltalk.compiler.assignment
-smalltalk.compiler.return smalltalk.selectors smalltalk.classes ;
+generalizations sequences.generalizations slots locals.types
+splitting math locals.rewrite.closures generic words combinators
+locals smalltalk.ast smalltalk.compiler.lexenv
+smalltalk.compiler.assignment smalltalk.compiler.return
+smalltalk.selectors smalltalk.classes ;
 IN: smalltalk.compiler
 
 GENERIC: compile-ast ( lexenv ast -- quot )