]> gitweb.factorcode.org Git - factor.git/commitdiff
Move general shufflers and combinators into generalizations, move narray there too
authorU-SLAVA-DFB8FF805\Slava <Slava@slava-dfb8ff805.(none)>
Tue, 8 Jul 2008 00:36:33 +0000 (19:36 -0500)
committerU-SLAVA-DFB8FF805\Slava <Slava@slava-dfb8ff805.(none)>
Tue, 8 Jul 2008 00:36:33 +0000 (19:36 -0500)
46 files changed:
core/bootstrap/primitives.factor
core/debugger/debugger.factor
core/sequences/sequences-docs.factor
core/sequences/sequences.factor
extra/arrays/lib/authors.txt [deleted file]
extra/arrays/lib/lib.factor [deleted file]
extra/arrays/lib/summary.txt [deleted file]
extra/arrays/lib/tags.txt [deleted file]
extra/bake/bake.factor [changed mode: 0644->0755]
extra/bake/fry/fry-tests.factor
extra/bitfields/bitfields.factor [changed mode: 0644->0755]
extra/combinators/cleave/cleave.factor [changed mode: 0644->0755]
extra/combinators/lib/lib-docs.factor
extra/combinators/lib/lib-tests.factor
extra/combinators/lib/lib.factor
extra/combinators/short-circuit/short-circuit.factor [changed mode: 0644->0755]
extra/descriptive/descriptive.factor
extra/generalizations/generalizations-docs.factor [new file with mode: 0755]
extra/generalizations/generalizations-tests.factor [new file with mode: 0755]
extra/generalizations/generalizations.factor [new file with mode: 0755]
extra/html/parser/analyzer/analyzer.factor
extra/inverse/inverse.factor
extra/koszul/koszul.factor
extra/logging/logging.factor
extra/math/blas/matrices/matrices.factor [changed mode: 0644->0755]
extra/math/blas/vectors/vectors.factor [changed mode: 0644->0755]
extra/math/vectors/vectors.factor
extra/mortar/mortar.factor [changed mode: 0644->0755]
extra/multi-methods/multi-methods.factor
extra/processing/processing.factor [changed mode: 0644->0755]
extra/reports/noise/noise.factor
extra/sequences/lib/lib.factor
extra/shuffle/authors.txt [deleted file]
extra/shuffle/shuffle-docs.factor [deleted file]
extra/shuffle/shuffle-tests.factor [deleted file]
extra/shuffle/shuffle.factor [deleted file]
extra/shuffle/summary.txt [deleted file]
extra/shuffle/tags.txt [deleted file]
extra/spheres/spheres.factor [changed mode: 0644->0755]
extra/springies/springies.factor [changed mode: 0644->0755]
extra/tools/memory/memory.factor [changed mode: 0644->0755]
extra/unix/unix.factor
extra/windows/com/com-tests.factor
extra/windows/com/syntax/syntax.factor
extra/windows/com/wrapper/wrapper.factor
extra/windows/user32/user32.factor

index 235f3894a11a3998d74009a631059e5737c849c7..6498dfde604533a2ede5d7f0bcb1698710293089 100755 (executable)
@@ -512,7 +512,7 @@ tuple
     { "unimplemented" "kernel.private" }
     { "gc-reset" "memory" }
 }
-dup length [ >r first2 r> make-primitive ] 2each
+[ >r first2 r> make-primitive ] each-index
 
 ! Bump build number
 "build" "kernel" create build 1+ 1quotation define
index f5316b08582c8bfcdc2cdb21a9603f3941bccac4..6759c43094fee377ac4a3ba4ade14d67e2943334 100755 (executable)
@@ -52,7 +52,7 @@ M: string error. print ;
         nl
         "The following restarts are available:" print
         nl
-        dup length [ restart. ] 2each
+        [ restart. ] each-index
     ] if ;
 
 : print-error ( error -- )
index dc8d7b9789a9ab84b6cd8733611361092b9e5a94..86fd9be3d76b274ac0b374cc6668b7391bc833f4 100755 (executable)
@@ -43,8 +43,8 @@ ARTICLE: "sequences-integers" "Integer sequences and counted loops"
 $nl
 "For example, the " { $link each } " combinator, given an integer, simply calls a quotation that number of times, pushing a counter on each iteration that ranges from 0 up to that integer:"
 { $example "3 [ . ] each" "0\n1\n2" }
-"A common idiom is to iterate over a sequence, while also maintaining a loop counter. This can be done using " { $link 2each } ":"
-{ $example "{ \"a\" \"b\" \"c\" } dup length [\n    \"Index: \" write . \"Element: \" write .\n] 2each" "Index: 0\nElement: \"a\"\nIndex: 1\nElement: \"b\"\nIndex: 2\nElement: \"c\"" }
+"A common idiom is to iterate over a sequence, while also maintaining a loop counter. This can be done using " { $link each-index } ", " { $link map-index } " and " { $link reduce-index } "."
+$nl
 "Combinators that produce new sequences, such as " { $link map } ", will output an array if the input is an integer." ;
 
 ARTICLE: "sequences-access" "Accessing sequence elements"
index 7560c8f73eddb5320a50bcf8a47d2d2a2f1b3333..1c6b96d0d5eadc410d0fd32de1e1f3d98cb58afd 100755 (executable)
@@ -426,6 +426,18 @@ PRIVATE>
 : follow ( obj quot -- seq )
     >r [ dup ] r> [ keep ] curry [ ] unfold nip ; inline
 
+: prepare-index ( seq quot -- seq n quot )
+    >r dup length r> ; inline
+
+: each-index ( seq quot -- )
+    prepare-index 2each ; inline
+
+: map-index ( seq quot -- )
+    prepare-index 2map ; inline
+
+: reduce-index ( seq identity quot -- )
+    swapd each-index ; inline
+
 : index ( obj seq -- n )
     [ = ] with find drop ;
 
diff --git a/extra/arrays/lib/authors.txt b/extra/arrays/lib/authors.txt
deleted file mode 100755 (executable)
index 6cfd5da..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Eduardo Cavazos
diff --git a/extra/arrays/lib/lib.factor b/extra/arrays/lib/lib.factor
deleted file mode 100644 (file)
index 6530e65..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-
-USING: kernel arrays sequences sequences.private macros ;
-
-IN: arrays.lib
-
-MACRO: narray ( n -- quot )
-    dup [ f <array> ] curry
-    swap <reversed> [
-        [ swap [ set-nth-unsafe ] keep ] curry
-    ] map concat append ;
diff --git a/extra/arrays/lib/summary.txt b/extra/arrays/lib/summary.txt
deleted file mode 100644 (file)
index 5ecd994..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Non-core array words
diff --git a/extra/arrays/lib/tags.txt b/extra/arrays/lib/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections
old mode 100644 (file)
new mode 100755 (executable)
index 4ce7bfb..db77d92
@@ -1,7 +1,7 @@
 
 USING: kernel parser namespaces sequences quotations arrays vectors splitting
        words math
-       macros arrays.lib combinators.lib combinators.conditional newfx ;
+       macros generalizations combinators.lib combinators.conditional newfx ;
 
 IN: bake
 
index 289e1b12fe453aa8e66d77d27ba3c3d106f62290..13202a78f51ad44276c5ce2188a1247e14a89c09 100755 (executable)
@@ -1,6 +1,6 @@
 
 USING: tools.test math prettyprint kernel io arrays vectors sequences
-       arrays.lib bake bake.fry ;
+       generalizations bake bake.fry ;
 
 IN: bake.fry.tests
 
old mode 100644 (file)
new mode 100755 (executable)
index 410fd4b..76e8d78
@@ -1,6 +1,6 @@
 USING: parser lexer kernel math sequences namespaces assocs summary
 words splitting math.parser arrays sequences.next mirrors
-shuffle compiler.units ;
+generalizations compiler.units ;
 IN: bitfields
 
 ! Example:
old mode 100644 (file)
new mode 100755 (executable)
index 9b8a790..f5aeeff
@@ -1,6 +1,6 @@
 
 USING: kernel combinators words quotations arrays sequences locals macros
-       shuffle combinators.lib arrays.lib fry ;
+       shuffle combinators.lib generalizations fry ;
 
 IN: combinators.cleave
 
index ccb1fca9a1f34636bd6a53a0803b768d30e05497..fe2f3556ef905e30eaa132d80c579ff6889b844a 100755 (executable)
@@ -11,46 +11,3 @@ HELP: generate
     "[ 20 random-prime ] [ 4 mod 3 = ] generate ."
     "526367"
 } ;
-
-HELP: ndip
-{ $values { "quot" quotation } { "n" number } }
-{ $description "A generalisation of " { $link dip } " that can work " 
-"for any stack depth. The quotation will be called with a stack that "
-"has 'n' items removed first. The 'n' items are then put back on the "
-"stack. The quotation can consume and produce any number of items."
-} 
-{ $examples
-  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 [ dup ] 1 ndip .s" "1\n1\n2" }
-  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip .s" "2\n3" }
-}
-{ $see-also dip 2dip } ;
-
-HELP: nslip
-{ $values { "n" number } }
-{ $description "A generalisation of " { $link slip } " that can work " 
-"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "
-"removed from the stack, the quotation called, and the items restored."
-} 
-{ $examples
-  { $example "USING: combinators.lib prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip .s" "99\n1\n2\n3\n4\n5" }
-}
-{ $see-also slip nkeep } ;
-
-HELP: nkeep
-{ $values { "quot" quotation } { "n" number } }
-{ $description "A generalisation of " { $link keep } " that can work " 
-"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "
-"saved, the quotation called, and the items restored."
-} 
-{ $examples
-  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s" "99\n1\n2\n3\n4\n5" }
-}
-{ $see-also keep nslip } ;
-
-! 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." } ;
-
-! HELP: ||
-! { $values { "quots" "a sequence of quotations with stack effect " { $snippet "( ... -- ... ? )" } } { "?" "a boolean" } }
-! { $description "Calls each quotation in turn; outputs " { $link t } " if one of the quotations output " { $link t } ", otherwise outputs " { $link f } ". As soon as a quotation outputs " { $link t } ", evaluation stops and subsequent quotations are not called." } ;
index e511e88fccd8b4104fe4c1d6367e3e669e7b7840..89d3ed7f7d7ef2f186c0059dd7e2deb34f02ad04 100755 (executable)
@@ -5,14 +5,6 @@ IN: combinators.lib.tests
 [ 5 ] [ [ 10 random ] [ 5 = ] generate ] unit-test
 [ t ] [ [ 10 random ] [ even? ] generate even? ] unit-test
 
-[ [ 99 ] 1 2 3 4 5 5 nslip ] must-infer
-{ 99 1 2 3 4 5 } [ [ 99 ] 1 2 3 4 5 5 nslip ] unit-test
-[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer
-{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test
-[ [ 1 2 3 + ] ] [ 1 2 3 [ + ] 3 ncurry ] unit-test
-[ { 1 2 } { 2 4 } { 3 8 } { 4 16 } { 5 32 } ] [ 1 2 3 4 5 [ dup 2^ 2array ] 5 napply ] unit-test
-[ [ dup 2^ 2array ] 5 napply ] must-infer
-
 [ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test
 
 [ { "foo" "xbarx" } ]
index 3fab4f62ae6ecad4143f5bf63fc89182eea5a78b..4af12a9ad6c6f5e915c0f397e8c5ada0aff1572e 100755 (executable)
@@ -4,7 +4,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel combinators fry namespaces quotations hashtables
 sequences assocs arrays inference effects math math.ranges
-arrays.lib shuffle macros continuations locals ;
+generalizations macros continuations locals ;
 
 IN: combinators.lib
 
@@ -12,30 +12,10 @@ IN: combinators.lib
 ! Generalized versions of core combinators
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-MACRO: ndip ( quot n -- ) dup saver -rot restorer 3append ;
-
-MACRO: nslip ( n -- ) dup saver [ call ] rot restorer 3append ;
-
 : 4slip ( quot a b c d -- a b c d ) 4 nslip ; inline
 
-MACRO: nkeep ( n -- )
-  [ ] [ 1+ ] [ ] tri
-  '[ [ , ndup ] dip , -nrot , nslip ] ;
-
 : 4keep ( w x y z quot -- w x y z ) 4 nkeep ; inline 
 
-MACRO: ncurry ( n -- ) [ curry ] n*quot ;
-
-MACRO:: nwith ( quot n -- )
-  [let | n' [ n 1+ ] |
-    [ n' -nrot [ n' nrot quot call ] n ncurry ] ] ;
-
-MACRO: napply ( n -- )
-  2 [a,b]
-  [ [ 1- ] [ ] bi
-    '[ , ntuck , nslip ] ]
-  map concat >quotation [ call ] append ;
-
 : 2with ( param1 param2 obj quot -- obj curry )
     with with ; inline
 
old mode 100644 (file)
new mode 100755 (executable)
index c74a2ca..a484e09
@@ -1,6 +1,6 @@
 
 USING: kernel combinators quotations arrays sequences assocs
-       locals shuffle macros fry ;
+       locals generalizations macros fry ;
 
 IN: combinators.short-circuit
 
index 3b55aa0521300929d1ba87353218b70f63e868d7..4b40747e9fa704282b7405aa0ad6f40470c9e249 100755 (executable)
@@ -1,6 +1,6 @@
 USING: words kernel sequences combinators.lib locals\r
 locals.private accessors parser namespaces continuations\r
-summary definitions arrays.lib arrays ;\r
+summary definitions generalizations arrays ;\r
 IN: descriptive\r
 \r
 ERROR: descriptive-error args underlying word ;\r
diff --git a/extra/generalizations/generalizations-docs.factor b/extra/generalizations/generalizations-docs.factor
new file mode 100755 (executable)
index 0000000..decabdc
--- /dev/null
@@ -0,0 +1,136 @@
+! Copyright (C) 2007 Chris Double.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: help.syntax help.markup kernel sequences quotations\r
+math ;\r
+IN: generalizations\r
+\r
+HELP: npick\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link dup } ", "\r
+{ $link over } " and " { $link pick } " that can work "\r
+"for any stack depth. The nth item down the stack will be copied and "\r
+"placed on the top of the stack."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 npick .s" "1\n2\n3\n4\n1" }\r
+}\r
+{ $see-also dup over pick } ;\r
+\r
+HELP: ndup\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link dup } ", "\r
+{ $link 2dup } " and " { $link 3dup } " that can work "\r
+"for any number of items. The n topmost items on the stack will be copied and "\r
+"placed on the top of the stack."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 ndup .s" "1\n2\n3\n4\n1\n2\n3\n4" }\r
+}\r
+{ $see-also dup 2dup 3dup } ;\r
+\r
+HELP: nnip\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link nip } " and " { $link 2nip }\r
+" that can work "\r
+"for any number of items."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 3 nnip .s" "4" }\r
+}\r
+{ $see-also nip 2nip } ;\r
+\r
+HELP: ndrop\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link drop }\r
+" that can work "\r
+"for any number of items."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 3 ndrop .s" "1" }\r
+}\r
+{ $see-also drop 2drop 3drop } ;\r
+\r
+HELP: nrot\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link rot } " that works for any "\r
+"number of items on the stack. "\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 nrot .s" "2\n3\n4\n1" }\r
+}\r
+{ $see-also rot -nrot } ;\r
+\r
+HELP: -nrot\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link -rot } " that works for any "\r
+"number of items on the stack. "\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 -nrot .s" "4\n1\n2\n3" }\r
+}\r
+{ $see-also rot nrot } ;\r
+\r
+HELP: nrev\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link spin } " that reverses any number of items at the top of the stack."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 nrev .s" "4\n3\n2\n1\n" }\r
+}\r
+{ $see-also rot nrot } ;\r
+\r
+HELP: ndip\r
+{ $values { "quot" quotation } { "n" number } }\r
+{ $description "A generalization of " { $link dip } " that can work " \r
+"for any stack depth. The quotation will be called with a stack that "\r
+"has 'n' items removed first. The 'n' items are then put back on the "\r
+"stack. The quotation can consume and produce any number of items."\r
+} \r
+{ $examples\r
+  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 [ dup ] 1 ndip .s" "1\n1\n2" }\r
+  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip .s" "2\n3" }\r
+}\r
+{ $see-also dip 2dip } ;\r
+\r
+HELP: nslip\r
+{ $values { "n" number } }\r
+{ $description "A generalization of " { $link slip } " that can work " \r
+"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "\r
+"removed from the stack, the quotation called, and the items restored."\r
+} \r
+{ $examples\r
+  { $example "USING: combinators.lib prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip .s" "99\n1\n2\n3\n4\n5" }\r
+}\r
+{ $see-also slip nkeep } ;\r
+\r
+HELP: nkeep\r
+{ $values { "quot" quotation } { "n" number } }\r
+{ $description "A generalization of " { $link keep } " that can work " \r
+"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "\r
+"saved, the quotation called, and the items restored."\r
+} \r
+{ $examples\r
+  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s" "99\n1\n2\n3\n4\n5" }\r
+}\r
+{ $see-also keep nslip } ;\r
+\r
+ARTICLE: "generalizations" "Generalized shuffle words and combinators"\r
+"A number of stack shuffling words and combinators for use in "\r
+"macros where the arity of the input quotations depends on an "\r
+"input parameter."\r
+{ $subsection narray }\r
+{ $subsection ndup }\r
+{ $subsection npick }\r
+{ $subsection nrot }\r
+{ $subsection -nrot }\r
+{ $subsection nnip }\r
+{ $subsection ndrop }\r
+{ $subsection nrev }\r
+{ $subsection ndip }\r
+{ $subsection nslip }\r
+{ $subsection nkeep }\r
+{ $subsection ncurry } \r
+{ $subsection nwith } \r
+{ $subsection napply } ;\r
+\r
+ABOUT: "generalizations"\r
diff --git a/extra/generalizations/generalizations-tests.factor b/extra/generalizations/generalizations-tests.factor
new file mode 100755 (executable)
index 0000000..1210143
--- /dev/null
@@ -0,0 +1,32 @@
+USING: tools.test generalizations kernel math arrays ;\r
+IN: generalizations.tests\r
+\r
+{ 1 2 3 4 1 } [ 1 2 3 4 4 npick ] unit-test\r
+{ 1 2 3 4 2 } [ 1 2 3 4 3 npick ] unit-test\r
+{ 1 2 3 4 3 } [ 1 2 3 4 2 npick ] unit-test\r
+{ 1 2 3 4 4 } [ 1 2 3 4 1 npick ] unit-test\r
+[ 1 1 ndup ] must-infer\r
+{ 1 1 } [ 1 1 ndup ] unit-test\r
+{ 1 2 1 2 } [ 1 2 2 ndup ] unit-test\r
+{ 1 2 3 1 2 3 } [ 1 2 3 3 ndup ] unit-test\r
+{ 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4 ndup ] unit-test\r
+[ 1 2 2 nrot ] must-infer\r
+{ 2 1 } [ 1 2 2 nrot ] unit-test\r
+{ 2 3 1 } [ 1 2 3 3 nrot ] unit-test\r
+{ 2 3 4 1 } [ 1 2 3 4 4 nrot ] unit-test\r
+[ 1 2 2 -nrot ] must-infer\r
+{ 2 1 } [ 1 2 2 -nrot ] unit-test\r
+{ 3 1 2 } [ 1 2 3 3 -nrot ] unit-test\r
+{ 4 1 2 3 } [ 1 2 3 4 4 -nrot ] unit-test\r
+[ 1 2 3 4 3 nnip ] must-infer\r
+{ 4 } [ 1 2 3 4 3 nnip ] unit-test\r
+[ 1 2 3 4 4 ndrop ] must-infer\r
+{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test\r
+\r
+[ [ 99 ] 1 2 3 4 5 5 nslip ] must-infer\r
+{ 99 1 2 3 4 5 } [ [ 99 ] 1 2 3 4 5 5 nslip ] unit-test\r
+[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer\r
+{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test\r
+[ [ 1 2 3 + ] ] [ 1 2 3 [ + ] 3 ncurry ] unit-test\r
+[ { 1 2 } { 2 4 } { 3 8 } { 4 16 } { 5 32 } ] [ 1 2 3 4 5 [ dup 2^ 2array ] 5 napply ] unit-test\r
+[ [ dup 2^ 2array ] 5 napply ] must-infer\r
diff --git a/extra/generalizations/generalizations.factor b/extra/generalizations/generalizations.factor
new file mode 100755 (executable)
index 0000000..6cbb135
--- /dev/null
@@ -0,0 +1,56 @@
+! Copyright (C) 2007, 2008 Chris Double, Doug Coleman.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: kernel sequences sequences.private namespaces math math.ranges\r
+combinators macros quotations fry locals arrays ;\r
+IN: generalizations\r
+\r
+MACRO: narray ( n -- quot )\r
+    dup [ f <array> ] curry\r
+    swap <reversed> [\r
+        [ swap [ set-nth-unsafe ] keep ] curry\r
+    ] map concat append ;\r
+\r
+MACRO: npick ( n -- )\r
+    1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;\r
+\r
+MACRO: ndup ( n -- )\r
+    dup '[ , npick ] n*quot ;\r
+\r
+MACRO: nrot ( n -- )\r
+    1- dup saver swap [ r> swap ] n*quot append ;\r
+\r
+MACRO: -nrot ( n -- )\r
+    1- dup [ swap >r ] n*quot swap restorer append ;\r
+\r
+MACRO: ndrop ( n -- )\r
+    [ drop ] n*quot ;\r
+\r
+: nnip ( n -- )\r
+    swap >r ndrop r> ; inline\r
+\r
+MACRO: ntuck ( n -- )\r
+    2 + [ dupd -nrot ] curry ;\r
+\r
+MACRO: nrev ( n -- quot )\r
+    1 [a,b] [ '[ , -nrot ] ] map concat ;\r
+\r
+MACRO: ndip ( quot n -- )\r
+    dup saver -rot restorer 3append ;\r
+\r
+MACRO: nslip ( n -- )\r
+    dup saver [ call ] rot restorer 3append ;\r
+\r
+MACRO: nkeep ( n -- )\r
+    [ ] [ 1+ ] [ ] tri\r
+    '[ [ , ndup ] dip , -nrot , nslip ] ;\r
+\r
+MACRO: ncurry ( n -- ) [ curry ] n*quot ;\r
+\r
+MACRO:: nwith ( quot n -- )\r
+    [let | n' [ n 1+ ] |\r
+        [ n' -nrot [ n' nrot quot call ] n ncurry ] ] ;\r
+\r
+MACRO: napply ( n -- )\r
+    2 [a,b]\r
+    [ [ 1- ] keep '[ , ntuck , nslip ] ]\r
+    map concat >quotation [ call ] append ;\r
index f6fccd42ecc189607e26627b19a1c99238c7dd5f..dca727b9dc5857a221ffc8cc8bb5a5f36645c07a 100755 (executable)
@@ -1,6 +1,6 @@
 USING: assocs html.parser kernel math sequences strings ascii
-arrays shuffle unicode.case namespaces splitting http
-sequences.lib accessors io combinators http.client urls ;
+arrays generalizations shuffle unicode.case namespaces splitting
+http sequences.lib accessors io combinators http.client urls ;
 IN: html.parser.analyzer
 
 TUPLE: link attributes clickable ;
index 4a35fbab24f20a4eae4cb95fd8cf5010a306f6b8..5a8ef4c78721ea9ccb5aa87b43812dda0bb14028 100755 (executable)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2007, 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel words summary slots quotations
-sequences assocs math arrays inference effects shuffle
+sequences assocs math arrays inference effects generalizations
 continuations debugger classes.tuple namespaces vectors
 bit-arrays byte-arrays strings sbufs math.functions macros
-sequences.private combinators mirrors combinators.lib
+sequences.private combinators mirrors
 combinators.short-circuit ;
 IN: inverse
 
index 188cfaa1cfe308a73a4a3daec954051456f02d95..37c2137433a4b32892c4c71b77c83361711d1ec3 100755 (executable)
@@ -257,11 +257,11 @@ DEFER: (d)
     [ laplacian-kernel ] graded-laplacian ;
 
 : graded-basis. ( seq -- )
-    dup length [
+    [
         "=== Degree " write pprint
         ": dimension " write dup length .
         [ alt. ] each
-    ] 2each ;
+    ] each-index ;
 
 : bigraded-triple ( u-deg z-deg bigraded-basis -- triple )
     #! d: C(u,z) ---> C(u+2,z-1)
@@ -289,11 +289,11 @@ DEFER: (d)
     [ laplacian-kernel ] bigraded-laplacian ;
 
 : bigraded-basis. ( seq -- )
-    dup length [
+    [
         "=== U-degree " write .
-        dup length [
+        [
             "  === Z-degree " write pprint
             ": dimension " write dup length .
             [ "  " write alt. ] each
-        ] 2each
-    ] 2each ;
+        ] each-index
+    ] each-index ;
index 37ea9ac50744ada1c587abfa7ed5292b952368e8..78a3002906fcf2a14541ca4f4c0b20a2f84b5b67 100755 (executable)
@@ -3,7 +3,7 @@
 USING: logging.server sequences namespaces concurrency.messaging\r
 words kernel arrays shuffle tools.annotations\r
 prettyprint.config prettyprint debugger io.streams.string\r
-splitting continuations effects arrays.lib parser strings\r
+splitting continuations effects generalizations parser strings\r
 quotations fry symbols accessors ;\r
 IN: logging\r
 \r
old mode 100644 (file)
new mode 100755 (executable)
index 99f20b4..c07dfca
@@ -2,7 +2,8 @@ USING: accessors alien alien.c-types arrays byte-arrays combinators
 combinators.lib combinators.short-circuit fry kernel locals macros
 math math.blas.cblas math.blas.vectors math.blas.vectors.private
 math.complex math.functions math.order multi-methods qualified
-sequences sequences.merged sequences.private shuffle symbols ;
+sequences sequences.merged sequences.private generalizations
+shuffle symbols ;
 QUALIFIED: syntax
 IN: math.blas.matrices
 
old mode 100644 (file)
new mode 100755 (executable)
index 3c92731..18370f1
@@ -1,7 +1,7 @@
 USING: accessors alien alien.c-types arrays byte-arrays combinators
 combinators.short-circuit fry kernel macros math math.blas.cblas
 math.complex math.functions math.order multi-methods qualified
-sequences sequences.private shuffle ;
+sequences sequences.private generalizations ;
 QUALIFIED: syntax
 IN: math.blas.vectors
 
index 5572a0cf53197ed3db3e8189d7368fe950d4fa98..b6ac45912377e4f881a359fd60359064123e9339 100755 (executable)
@@ -25,7 +25,7 @@ IN: math.vectors
 : normalize ( u -- v ) dup norm v/n ;
 
 : set-axis ( u v axis -- w )
-    dup length [ >r zero? 2over ? r> swap nth ] 2map 2nip ;
+    [ >r zero? 2over ? r> swap nth ] map-index 2nip ;
 
 HINTS: vneg { array } ;
 HINTS: norm-sq { array } ;
old mode 100644 (file)
new mode 100755 (executable)
index 1b5b6f2..5b7f335
@@ -1,6 +1,6 @@
 
 USING: kernel io parser lexer words namespaces quotations arrays assocs sequences
-       splitting grouping math shuffle ;
+       splitting grouping math generalizations ;
 
 IN: mortar
 
index c8128c33eeafd1160e94441048c87bfb760dfe17..69dca2affc22e760b9f9df3adc2d5b490c9a06a6 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math sequences vectors classes classes.algebra
 combinators arrays words assocs parser namespaces definitions
-prettyprint prettyprint.backend quotations arrays.lib
+prettyprint prettyprint.backend quotations generalizations
 debugger io compiler.units kernel.private effects accessors
 hashtables sorting shuffle math.order sets ;
 IN: multi-methods
old mode 100644 (file)
new mode 100755 (executable)
index e089b15..fb9f321
@@ -1,7 +1,7 @@
 
 USING: kernel namespaces threads combinators sequences arrays
        math math.functions math.ranges random
-       opengl.gl opengl.glu vars multi-methods shuffle
+       opengl.gl opengl.glu vars multi-methods generalizations shuffle
        ui
        ui.gestures
        ui.gadgets
index 32a43a4fb4d9ef97543aaba9520bab571216e907..ff88abad612d25c6b105fa54fa7a315fd3792421 100755 (executable)
@@ -1,7 +1,7 @@
-USING: accessors assocs math kernel shuffle combinators.lib\r
+USING: accessors assocs math kernel shuffle generalizations\r
 words quotations arrays combinators sequences math.vectors\r
 io.styles prettyprint vocabs sorting io generic locals.private\r
-math.statistics math.order ;\r
+math.statistics math.order combinators.lib ;\r
 IN: reports.noise\r
 \r
 : badness ( word -- n )\r
index 1debe3f91b7d163a8f424bb8573cec88ce06882c..3b54abfeab46588fef54100f698df4cf8973411c 100755 (executable)
@@ -4,7 +4,8 @@
 USING: combinators.lib kernel sequences math namespaces assocs 
 random sequences.private shuffle math.functions
 arrays math.parser math.private sorting strings ascii macros
-assocs.lib quotations hashtables math.order locals ;
+assocs.lib quotations hashtables math.order locals
+generalizations ;
 IN: sequences.lib
 
 : each-withn ( seq quot n -- ) nwith each ; inline
@@ -24,21 +25,6 @@ MACRO: firstn ( n -- )
     concat >quotation
     [ drop ] compose ;
 
-: prepare-index ( seq quot -- seq n quot )
-    >r dup length r> ; inline
-
-: each-index ( seq quot -- )
-    #! quot: ( elt index -- )
-    prepare-index 2each ; inline
-
-: map-index ( seq quot -- )
-    #! quot: ( elt index -- obj )
-    prepare-index 2map ; inline
-
-: reduce-index ( seq identity quot -- )
-    #! quot: ( prev elt index -- next )
-    swapd each-index ; inline
-
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : each-percent ( seq quot -- )
diff --git a/extra/shuffle/authors.txt b/extra/shuffle/authors.txt
deleted file mode 100644 (file)
index 26093b4..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Chris Double
-Doug Coleman
diff --git a/extra/shuffle/shuffle-docs.factor b/extra/shuffle/shuffle-docs.factor
deleted file mode 100755 (executable)
index 4caace3..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-! Copyright (C) 2007 Chris Double.
-! See http://factorcode.org/license.txt for BSD license.
-USING: help.syntax help.markup kernel sequences ;
-IN: shuffle
-
-HELP: npick
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link dup } ", "
-{ $link over } " and " { $link pick } " that can work "
-"for any stack depth. The nth item down the stack will be copied and "
-"placed on the top of the stack."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 npick .s" "1\n2\n3\n4\n1" }
-}
-{ $see-also dup over pick } ;
-
-HELP: ndup
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link dup } ", "
-{ $link 2dup } " and " { $link 3dup } " that can work "
-"for any number of items. The n topmost items on the stack will be copied and "
-"placed on the top of the stack."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 ndup .s" "1\n2\n3\n4\n1\n2\n3\n4" }
-}
-{ $see-also dup 2dup 3dup } ;
-
-HELP: nnip
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link nip } " and " { $link 2nip }
-" that can work "
-"for any number of items."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 3 nnip .s" "4" }
-}
-{ $see-also nip 2nip } ;
-
-HELP: ndrop
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link drop }
-" that can work "
-"for any number of items."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 3 ndrop .s" "1" }
-}
-{ $see-also drop 2drop 3drop } ;
-
-HELP: nrot
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link rot } " that works for any "
-"number of items on the stack. "
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 nrot .s" "2\n3\n4\n1" }
-}
-{ $see-also rot -nrot } ;
-
-HELP: -nrot
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link -rot } " that works for any "
-"number of items on the stack. "
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 -nrot .s" "4\n1\n2\n3" }
-}
-{ $see-also rot nrot } ;
-
-ARTICLE: { "shuffle" "overview" } "Extra shuffle words"
-"A number of stack shuffling words for those rare times when you "
-"need to deal with tricky stack situations and can't refactor the "
-"code to work around it."
-{ $subsection ndup }
-{ $subsection npick }
-{ $subsection nrot }
-{ $subsection -nrot }
-{ $subsection nnip }
-{ $subsection ndrop }  ;
-
-IN: shuffle
-ABOUT: { "shuffle" "overview" }
\ No newline at end of file
diff --git a/extra/shuffle/shuffle-tests.factor b/extra/shuffle/shuffle-tests.factor
deleted file mode 100755 (executable)
index 9f2b8e0..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-USING: arrays shuffle kernel math tools.test inference words ;
-
-[ 8 ] [ 5 6 7 8 3nip ] unit-test
-{ 1 2 3 4 1 } [ 1 2 3 4 4 npick ] unit-test
-{ 1 2 3 4 2 } [ 1 2 3 4 3 npick ] unit-test
-{ 1 2 3 4 3 } [ 1 2 3 4 2 npick ] unit-test
-{ 1 2 3 4 4 } [ 1 2 3 4 1 npick ] unit-test
-{ t } [ [ 1 1 ndup ] infer >boolean ] unit-test
-{ 1 1 } [ 1 1 ndup ] unit-test
-{ 1 2 1 2 } [ 1 2 2 ndup ] unit-test
-{ 1 2 3 1 2 3 } [ 1 2 3 3 ndup ] unit-test
-{ 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4 ndup ] unit-test
-{ t } [ [ 1 2 2 nrot ] infer >boolean ] unit-test
-{ 2 1 } [ 1 2 2 nrot ] unit-test
-{ 2 3 1 } [ 1 2 3 3 nrot ] unit-test
-{ 2 3 4 1 } [ 1 2 3 4 4 nrot ] unit-test
-{ t } [ [ 1 2 2 -nrot ] infer >boolean ] unit-test
-{ 2 1 } [ 1 2 2 -nrot ] unit-test
-{ 3 1 2 } [ 1 2 3 3 -nrot ] unit-test
-{ 4 1 2 3 } [ 1 2 3 4 4 -nrot ] unit-test
-{ t } [ [ 1 2 3 4 3 nnip ] infer >boolean ] unit-test
-{ 4 } [ 1 2 3 4 3 nnip ] unit-test
-{ t } [ [ 1 2 3 4 4 ndrop ] infer >boolean ] unit-test
-{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test
-[ 3 1 2 3 ] [ 1 2 3 tuckd ] unit-test
diff --git a/extra/shuffle/shuffle.factor b/extra/shuffle/shuffle.factor
deleted file mode 100644 (file)
index 2366d15..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-! Copyright (C) 2007 Chris Double, Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences namespaces math inference.transforms
-       combinators macros quotations math.ranges fry ;
-
-IN: shuffle
-
-MACRO: npick ( n -- ) 1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;
-
-MACRO: ndup ( n -- ) dup [ npick ] curry n*quot ;
-
-MACRO: nrot ( n -- ) 1- dup saver swap [ r> swap ] n*quot append ;
-
-MACRO: -nrot ( n -- ) 1- dup [ swap >r ] n*quot swap restorer append ;
-
-MACRO: ndrop ( n -- ) [ drop ] n*quot ;
-
-: nnip ( n -- ) swap >r ndrop r> ; inline
-
-MACRO: ntuck ( n -- ) 2 + '[ dup , -nrot ] ;
-
-: 2swap ( x y z t -- z t x y ) rot >r rot r> ; inline
-
-: nipd ( a b c -- b c ) rot drop ; inline
-
-: 3nip ( a b c d -- d ) 3 nnip ; inline
-
-: 4nip ( a b c d e -- e ) 4 nnip ; inline
-
-: 4dup ( a b c d -- a b c d a b c d ) 4 ndup ; inline
-
-: 4drop ( a b c d -- ) 3drop drop ; inline
-
-: tuckd ( x y z -- z x y z ) 2 ntuck ; inline
-
-MACRO: nrev ( n -- quot )
-  [ 1+ ] map
-  reverse
-  [ [ -nrot ] curry ] map concat ;
diff --git a/extra/shuffle/summary.txt b/extra/shuffle/summary.txt
deleted file mode 100644 (file)
index 12c22b8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Additional shuffle words
diff --git a/extra/shuffle/tags.txt b/extra/shuffle/tags.txt
deleted file mode 100644 (file)
index f427429..0000000
+++ /dev/null
@@ -1 +0,0 @@
-extensions
old mode 100644 (file)
new mode 100755 (executable)
index 9d06987..dff7313
@@ -1,6 +1,6 @@
 USING: kernel opengl.demo-support opengl.gl opengl.shaders opengl.framebuffers
 opengl multiline ui.gadgets accessors sequences ui.render ui math 
-arrays arrays.lib combinators ;
+arrays generalizations combinators ;
 IN: spheres
 
 STRING: plane-vertex-shader
old mode 100644 (file)
new mode 100755 (executable)
index cd6e1a7..1856115
@@ -1,6 +1,6 @@
 
 USING: kernel combinators sequences arrays math math.vectors
-       shuffle vars ;
+       generalizations vars ;
 
 IN: springies
 
old mode 100644 (file)
new mode 100755 (executable)
index 83da7f2..f61694d
@@ -33,10 +33,10 @@ IN: tools.memory
     [ [ write-cell ] each ] with-row ;
 
 : (data-room.) ( -- )
-    data-room 2 <groups> dup length [
+    data-room 2 <groups> [
         [ first2 ] [ number>string "Generation " prepend ] bi*
         write-total/used/free
-    ] 2each
+    ] each-index
     "Decks" write-total
     "Cards" write-total ;
 
index 07eb2950fad1a64bcb2668916841bdea9e11a611..083700493d02702f2fde96c1c2973b28541b6511 100755 (executable)
@@ -4,7 +4,7 @@
 USING: alien alien.c-types alien.syntax kernel libc structs sequences
        continuations byte-arrays strings
        math namespaces system combinators vocabs.loader qualified
-       accessors inference macros locals shuffle arrays.lib 
+       accessors inference macros locals generalizations 
        unix.types debugger io prettyprint ;
 
 IN: unix
index c04fd8f544b278d3bd1eb4db605361f3534075d5..394bec2dfba3af9d4b873b8f09ddb9cb4e70de2a 100755 (executable)
@@ -1,5 +1,5 @@
 USING: kernel windows.com windows.com.syntax windows.ole32
-alien alien.syntax tools.test libc alien.c-types arrays.lib 
+alien alien.syntax tools.test libc alien.c-types 
 namespaces arrays continuations accessors math windows.com.wrapper
 windows.com.wrapper.private destructors effects ;
 IN: windows.com.tests
index e0ea65e8be2d49c37ef1a1afc02f0f5ee4bd83b3..dd7d058a77a8f7c6db1e122ad66d988889c0210d 100755 (executable)
@@ -1,6 +1,6 @@
 USING: alien alien.c-types effects kernel windows.ole32
-parser lexer splitting grouping sequences.lib sequences namespaces
-assocs quotations shuffle accessors words macros alien.syntax
+parser lexer splitting grouping sequences namespaces
+assocs quotations generalizations accessors words macros alien.syntax
 fry arrays ;
 IN: windows.com.syntax
 
index 266439ad799a848a01fb3524e6286fc0b3e2421d..79a945e7de50c14be4a006d794f7dfc51f802731 100755 (executable)
@@ -1,6 +1,6 @@
 USING: alien alien.c-types windows.com.syntax
 windows.com.syntax.private windows.com continuations kernel
-sequences.lib namespaces windows.ole32 libc vocabs
+namespaces windows.ole32 libc vocabs
 assocs accessors arrays sequences quotations combinators
 math words compiler.units destructors fry
 math.parser combinators.lib ;
index 49a04dcb48625ca5de78a5017b57dc2e35bfa309..1c1df52da8ad949e8bd528f77f3e14a77631bd6b 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2006 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax parser namespaces kernel math
-windows.types shuffle math.bitfields alias ;
+windows.types generalizations math.bitfields alias ;
 IN: windows.user32
 
 ! HKL for ActivateKeyboardLayout