From 9356da6fb3eb86fd340751f815daaba9a472e833 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 14 Jan 2010 17:20:43 -0600 Subject: [PATCH] Fix a few integers-as-sequences in docs --- basis/grouping/grouping-docs.factor | 4 ++-- basis/math/combinatorics/combinatorics-docs.factor | 4 ++-- core/sequences/sequences-docs.factor | 12 +++++------- extra/infix/infix-docs.factor | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/basis/grouping/grouping-docs.factor b/basis/grouping/grouping-docs.factor index e1044b0feb..2c2fee1d70 100644 --- a/basis/grouping/grouping-docs.factor +++ b/basis/grouping/grouping-docs.factor @@ -52,7 +52,7 @@ HELP: { $examples { $example "USING: arrays kernel prettyprint sequences grouping ;" - "9 >array 3 reverse! concat >array ." "{ 6 7 8 3 4 5 0 1 2 }" + "9 iota >array 3 reverse! concat >array ." "{ 6 7 8 3 4 5 0 1 2 }" } { $example "USING: kernel prettyprint sequences grouping ;" @@ -67,7 +67,7 @@ HELP: { $examples { $example "USING: arrays kernel prettyprint sequences grouping ;" - "9 >array 3 " + "9 iota >array 3 " "dup [ reverse! drop ] each concat >array ." "{ 2 1 0 5 4 3 8 7 6 }" } diff --git a/basis/math/combinatorics/combinatorics-docs.factor b/basis/math/combinatorics/combinatorics-docs.factor index 10584f2004..ec3cd6ee76 100644 --- a/basis/math/combinatorics/combinatorics-docs.factor +++ b/basis/math/combinatorics/combinatorics-docs.factor @@ -31,7 +31,7 @@ HELP: permutation { $notes "Permutations are 0-based and a bounds error will be thrown if " { $snippet "n" } " is larger than " { $snippet "seq length factorial 1 -" } "." } { $examples { $example "USING: math.combinatorics prettyprint ;" - "1 3 permutation ." "{ 0 2 1 }" } + "1 { 0 1 2 } permutation ." "{ 0 2 1 }" } { $example "USING: math.combinatorics prettyprint ;" "5 { \"apple\" \"banana\" \"orange\" } permutation ." "{ \"orange\" \"banana\" \"apple\" }" } } ; @@ -41,7 +41,7 @@ HELP: all-permutations { $description "Outputs a sequence containing all permutations of " { $snippet "seq" } " in lexicographical order." } { $examples { $example "USING: math.combinatorics prettyprint ;" - "3 all-permutations ." "{ { 0 1 2 } { 0 2 1 } { 1 0 2 } { 1 2 0 } { 2 0 1 } { 2 1 0 } }" } + "{ 0 1 2 } all-permutations ." "{ { 0 1 2 } { 0 2 1 } { 1 0 2 } { 1 2 0 } { 2 0 1 } { 2 1 0 } }" } } ; HELP: each-permutation diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 5985246425..a33aaa21d2 100644 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -999,7 +999,7 @@ HELP: pusher { "quot" quotation } { "accum" vector } } { $description "Creates a new vector to accumulate the values which return true for a predicate. Returns a new quotation which accepts an object to be tested and stored in the accumulator if the test yields true. The accumulator is left on the stack for convenience." } { $example "! Find all the even numbers:" "USING: prettyprint sequences math kernel ;" - "10 [ even? ] pusher [ each ] dip ." + "10 iota [ even? ] pusher [ each ] dip ." "V{ 0 2 4 6 8 }" } { $notes "Used to implement the " { $link filter } " word. Compare this word with " { $link accumulator } ", which is an unfiltering version." } ; @@ -1241,7 +1241,7 @@ HELP: binary-reduce { $description "Like " { $link reduce } ", but splits the sequence in half recursively until each sequence is small enough, and calls the quotation on these smaller sequences. If the quotation computes values that depend on the size of their input, such as bignum arithmetic, then this algorithm can be more efficient than using " { $link reduce } "." } { $examples "Computing factorial:" { $example "USING: prettyprint sequences math ;" - "40 rest-slice 1 [ * ] binary-reduce ." + "40 iota rest-slice 1 [ * ] binary-reduce ." "20397882081197443358640281739902897356800000000" } } ; @@ -1413,14 +1413,12 @@ $nl "Virtual sequences can be implemented with the " { $link "virtual-sequences-protocol" } ", by translating an index in the virtual sequence into an index in another sequence." ; ARTICLE: "sequences-integers" "Counted loops" -"Integers support the sequence protocol in a trivial fashion; a non-negative integer presents its non-negative predecessors as elements. For example, the integer 3, when viewed as a sequence, contains the elements 0, 1, and 2. This is very useful for performing counted loops." +"Integers do not support the sequence protocol, but can be turned into virtual sequences using the " { $link iota } " word. For example, the integer 3, when wrapped in an " { $link iota } ", contains the elements 0, 1, and 2. This is very useful for performing counted loops. Note that since this is a virtual sequence, the elements of the sequence are not actually stored, but calculated on demand." $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" } +"As another example, the " { $link each } " combinator, given a sequence, simply calls a quotation on each element of the sequence, ranging from 0 up to the integer wrapped by iota:" +{ $example "3 iota [ . ] 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 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." -$nl "More elaborate counted loops can be performed with " { $link "math.ranges" } "." ; ARTICLE: "sequences-if" "Control flow with sequences" diff --git a/extra/infix/infix-docs.factor b/extra/infix/infix-docs.factor index 917480dd3f..9c42bf256b 100644 --- a/extra/infix/infix-docs.factor +++ b/extra/infix/infix-docs.factor @@ -68,9 +68,9 @@ $nl "Please note: in Factor " { $emphasis "fixnums are sequences too." } " If you are not careful with sequence accesses you may introduce subtle bugs:" { $example "USING: arrays infix locals ;" - ":: add-2nd-element ( x y -- res )" + ":: add-2nd-elements ( x y -- res )" " [infix x[1] + y[1] infix] ;" - "{ 1 2 3 } 5 add-2nd-element ." + "{ 1 2 3 } { 0 1 2 3 } add-2nd-elements ." "3" } ; -- 2.34.1