From ea726f5680d9e5bce996cfa6df5c3418799c513a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 18 May 2010 18:36:47 -0400 Subject: [PATCH] Move remaining sequence operations from generalizations to sequences.generalizations where they belong --- basis/alien/fortran/fortran.factor | 15 +-- basis/bootstrap/image/image.factor | 10 +- basis/checksums/sha/sha.factor | 2 +- basis/combinators/smart/smart.factor | 4 +- basis/compiler/cfg/def-use/def-use.factor | 6 +- .../intrinsics/simd/backend/backend.factor | 2 +- .../preferred/preferred.factor | 7 +- basis/compiler/codegen/fixup/fixup.factor | 22 +++-- .../propagation/transforms/transforms.factor | 7 +- .../generalizations-docs.factor | 92 +------------------ .../generalizations-tests.factor | 14 --- basis/generalizations/generalizations.factor | 35 ------- basis/inverse/inverse.factor | 2 +- basis/locals/rewrite/sugar/sugar.factor | 2 +- basis/logging/logging.factor | 3 +- .../vectors/simd/intrinsics/intrinsics.factor | 4 +- basis/math/vectors/simd/simd.factor | 3 +- basis/models/arrow/smart/smart.factor | 3 +- basis/models/range/range.factor | 3 +- basis/nmake/nmake.factor | 2 +- basis/opengl/opengl.factor | 4 +- .../generalizations-docs.factor | 92 ++++++++++++++++++- .../generalizations-tests.factor | 14 +++ .../generalizations/generalizations.factor | 35 +++++++ basis/shuffle/shuffle.factor | 6 +- basis/tools/annotations/annotations.factor | 7 +- basis/tools/memory/memory.factor | 5 +- basis/tools/test/test.factor | 14 +-- basis/unix/unix.factor | 4 +- basis/xml/syntax/inverse/inverse.factor | 4 +- basis/xml/syntax/syntax.factor | 12 +-- extra/audio/engine/engine.factor | 3 +- extra/c/lexer/lexer.factor | 4 +- extra/constructors/constructors.factor | 5 +- extra/db/info/info.factor | 15 --- extra/descriptive/descriptive.factor | 8 +- extra/math/matrices/simd/simd.factor | 7 +- extra/multi-methods/multi-methods.factor | 6 +- extra/smalltalk/compiler/compiler.factor | 9 +- 39 files changed, 245 insertions(+), 247 deletions(-) delete mode 100644 extra/db/info/info.factor diff --git a/basis/alien/fortran/fortran.factor b/basis/alien/fortran/fortran.factor index 27bd183a2e..3d87431084 100755 --- a/basis/alien/fortran/fortran.factor +++ b/basis/alien/fortran/fortran.factor @@ -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 diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index 62240f73ce..68fbf55105 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -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 diff --git a/basis/checksums/sha/sha.factor b/basis/checksums/sha/sha.factor index af0f95fa76..82d2c2b491 100644 --- a/basis/checksums/sha/sha.factor +++ b/basis/checksums/sha/sha.factor @@ -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 diff --git a/basis/combinators/smart/smart.factor b/basis/combinators/smart/smart.factor index a907d2d297..c0ce938abb 100644 --- a/basis/combinators/smart/smart.factor +++ b/basis/combinators/smart/smart.factor @@ -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' ) diff --git a/basis/compiler/cfg/def-use/def-use.factor b/basis/compiler/cfg/def-use/def-use.factor index 93c1a53b44..a2a0b2d8be 100644 --- a/basis/compiler/cfg/def-use/def-use.factor +++ b/basis/compiler/cfg/def-use/def-use.factor @@ -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 ; diff --git a/basis/compiler/cfg/intrinsics/simd/backend/backend.factor b/basis/compiler/cfg/intrinsics/simd/backend/backend.factor index f84e826f19..bc1e04a2f3 100644 --- a/basis/compiler/cfg/intrinsics/simd/backend/backend.factor +++ b/basis/compiler/cfg/intrinsics/simd/backend/backend.factor @@ -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 diff --git a/basis/compiler/cfg/representations/preferred/preferred.factor b/basis/compiler/cfg/representations/preferred/preferred.factor index e1a9ec0d93..8ca91c4389 100644 --- a/basis/compiler/cfg/representations/preferred/preferred.factor +++ b/basis/compiler/cfg/representations/preferred/preferred.factor @@ -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 diff --git a/basis/compiler/codegen/fixup/fixup.factor b/basis/compiler/codegen/fixup/fixup.factor index 518efc8055..9e366cd408 100644 --- a/basis/compiler/codegen/fixup/fixup.factor +++ b/basis/compiler/codegen/fixup/fixup.factor @@ -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 diff --git a/basis/compiler/tree/propagation/transforms/transforms.factor b/basis/compiler/tree/propagation/transforms/transforms.factor index 3d2d7ac298..a89238dc5c 100644 --- a/basis/compiler/tree/propagation/transforms/transforms.factor +++ b/basis/compiler/tree/propagation/transforms/transforms.factor @@ -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 diff --git a/basis/generalizations/generalizations-docs.factor b/basis/generalizations/generalizations-docs.factor index d21b2b022c..168f2dfcd2 100644 --- a/basis/generalizations/generalizations-docs.factor +++ b/basis/generalizations/generalizations-docs.factor @@ -2,59 +2,10 @@ USING: help.syntax help.markup kernel sequences quotations math arrays combinators ; IN: 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: nsum { $values { "n" integer } } { $description "Adds the top " { $snippet "n" } " stack values." } ; -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: npick { $values { "n" integer } } { $description "A generalization of " { $link dup } ", " @@ -302,46 +253,6 @@ HELP: n*quot } { $description "Construct a quotation containing the contents of " { $snippet "seq" } " repeated " { $snippet "n"} " times." } ; -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 - -ARTICLE: "sequence-generalizations" "Generalized sequence operations" -{ $subsections - narray - nsequence - firstn - set-firstn - nappend - nappend-as -} ; - ARTICLE: "shuffle-generalizations" "Generalized shuffle words" { $subsections ndup @@ -381,11 +292,10 @@ ARTICLE: "generalizations" "Generalized shuffle words and combinators" "macros where the arity of the input quotations depends on an " "input parameter." { $subsections - "sequence-generalizations" "shuffle-generalizations" "combinator-generalizations" "other-generalizations" } -"Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence iteration combinators." ; +"Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence operations." ; ABOUT: "generalizations" diff --git a/basis/generalizations/generalizations-tests.factor b/basis/generalizations/generalizations-tests.factor index 477be4a20f..9b6374ca5f 100644 --- a/basis/generalizations/generalizations-tests.factor +++ b/basis/generalizations/generalizations-tests.factor @@ -39,24 +39,10 @@ IN: generalizations.tests [ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test -[ 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 - [ 4 5 1 2 3 ] [ 1 2 3 4 5 2 3 mnswap ] unit-test [ 1 2 3 4 5 6 ] [ 1 2 3 4 5 6 2 4 mnswap 4 2 mnswap ] 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 - [ 17 ] [ 3 1 3 3 7 5 nsum ] unit-test { 4 1 } [ 4 nsum ] must-infer-as diff --git a/basis/generalizations/generalizations.factor b/basis/generalizations/generalizations.factor index ac5ff3dee0..2c6a9f1a21 100644 --- a/basis/generalizations/generalizations.factor +++ b/basis/generalizations/generalizations.factor @@ -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 - diff --git a/basis/inverse/inverse.factor b/basis/inverse/inverse.factor index 3485b3efa7..b4a3b72b3c 100644 --- a/basis/inverse/inverse.factor +++ b/basis/inverse/inverse.factor @@ -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 ; diff --git a/basis/locals/rewrite/sugar/sugar.factor b/basis/locals/rewrite/sugar/sugar.factor index 9dfc733fff..110cc6ad81 100644 --- a/basis/locals/rewrite/sugar/sugar.factor +++ b/basis/locals/rewrite/sugar/sugar.factor @@ -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 diff --git a/basis/logging/logging.factor b/basis/logging/logging.factor index c8179108ef..7542c269bd 100644 --- a/basis/logging/logging.factor +++ b/basis/logging/logging.factor @@ -4,7 +4,8 @@ USING: logging.server sequences namespaces concurrency.messaging words kernel arrays shuffle tools.annotations prettyprint.config prettyprint debugger io.streams.string splitting continuations effects generalizations parser strings -quotations fry accessors math assocs math.order ; +quotations fry accessors math assocs math.order +sequences.generalizations ; IN: logging SYMBOLS: DEBUG NOTICE WARNING ERROR CRITICAL ; diff --git a/basis/math/vectors/simd/intrinsics/intrinsics.factor b/basis/math/vectors/simd/intrinsics/intrinsics.factor index 021ffc5a0c..c7d650e1e6 100644 --- a/basis/math/vectors/simd/intrinsics/intrinsics.factor +++ b/basis/math/vectors/simd/intrinsics/intrinsics.factor @@ -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 diff --git a/basis/math/vectors/simd/simd.factor b/basis/math/vectors/simd/simd.factor index 73a6faeee8..708fcaa190 100644 --- a/basis/math/vectors/simd/simd.factor +++ b/basis/math/vectors/simd/simd.factor @@ -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 diff --git a/basis/models/arrow/smart/smart.factor b/basis/models/arrow/smart/smart.factor index 7c29310a97..3398183edb 100644 --- a/basis/models/arrow/smart/smart.factor +++ b/basis/models/arrow/smart/smart.factor @@ -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: ( quot -- quot' ) diff --git a/basis/models/range/range.factor b/basis/models/range/range.factor index c39c80c7d1..9a4584a9a2 100644 --- a/basis/models/range/range.factor +++ b/basis/models/range/range.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel models arrays sequences math math.order -models.product generalizations math.functions ; +models.product generalizations sequences.generalizations +math.functions ; FROM: models.product => product ; IN: models.range diff --git a/basis/nmake/nmake.factor b/basis/nmake/nmake.factor index 61a0950ce4..912bb17218 100644 --- a/basis/nmake/nmake.factor +++ b/basis/nmake/nmake.factor @@ -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 diff --git a/basis/opengl/opengl.factor b/basis/opengl/opengl.factor index 1f6205e64f..6dcb4110a2 100644 --- a/basis/opengl/opengl.factor +++ b/basis/opengl/opengl.factor @@ -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 diff --git a/basis/sequences/generalizations/generalizations-docs.factor b/basis/sequences/generalizations/generalizations-docs.factor index 30ad1ea628..af1f673170 100644 --- a/basis/sequences/generalizations/generalizations-docs.factor +++ b/basis/sequences/generalizations/generalizations-docs.factor @@ -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 diff --git a/basis/sequences/generalizations/generalizations-tests.factor b/basis/sequences/generalizations/generalizations-tests.factor index d1861b8f9d..ff2b705930 100644 --- a/basis/sequences/generalizations/generalizations-tests.factor +++ b/basis/sequences/generalizations/generalizations-tests.factor @@ -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 ) diff --git a/basis/sequences/generalizations/generalizations.factor b/basis/sequences/generalizations/generalizations.factor index 60b1a8a011..8401930db3 100644 --- a/basis/sequences/generalizations/generalizations.factor +++ b/basis/sequences/generalizations/generalizations.factor @@ -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 ] ] diff --git a/basis/shuffle/shuffle.factor b/basis/shuffle/shuffle.factor index b826606df5..2659ed3280 100644 --- a/basis/shuffle/shuffle.factor +++ b/basis/shuffle/shuffle.factor @@ -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 > "vocab:" "/dbinfo.txt" surround utf8 file-lines ; -SYNTAX: get-psql-info get-info 5 firstn - { - [ >>host ] - [ >>port ] - [ >>username ] - [ [ f ] [ ] if-empty >>password ] - [ >>database ] - } spread suffix! ; - -SYNTAX: get-sqlite-info get-info first suffix! ; diff --git a/extra/descriptive/descriptive.factor b/extra/descriptive/descriptive.factor index 5c6b5028f8..dec94d76bf 100644 --- a/extra/descriptive/descriptive.factor +++ b/extra/descriptive/descriptive.factor @@ -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 ; diff --git a/extra/math/matrices/simd/simd.factor b/extra/math/matrices/simd/simd.factor index 26ad8bb4d7..5ccd243a54 100644 --- a/extra/math/matrices/simd/simd.factor +++ b/extra/math/matrices/simd/simd.factor @@ -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) ; diff --git a/extra/multi-methods/multi-methods.factor b/extra/multi-methods/multi-methods.factor index a65e459a7c..ebe60e00f6 100644 --- a/extra/multi-methods/multi-methods.factor +++ b/extra/multi-methods/multi-methods.factor @@ -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 diff --git a/extra/smalltalk/compiler/compiler.factor b/extra/smalltalk/compiler/compiler.factor index 0c1a5c07d1..fcb76c4135 100644 --- a/extra/smalltalk/compiler/compiler.factor +++ b/extra/smalltalk/compiler/compiler.factor @@ -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 ) -- 2.34.1