diff --git a/basis/disjoint-sets/disjoint-sets.factor b/basis/disjoint-sets/disjoint-sets.factor index f48129fbd4..77e4a53f7b 100644 --- a/basis/disjoint-sets/disjoint-sets.factor +++ b/basis/disjoint-sets/disjoint-sets.factor @@ -88,6 +88,14 @@ M:: disjoint-set equate ( a b disjoint-set -- ) disjoint-set link-sets ] if ; +: equate-all-with ( seq a disjoint-set -- ) + '[ , , equate ] each ; + +: equate-all ( seq disjoint-set -- ) + over dup empty? [ 2drop ] [ + [ unclip-slice ] dip equate-all-with + ] if ; + M: disjoint-set clone [ parents>> ] [ ranks>> ] [ counts>> ] tri [ clone ] tri@ disjoint-set boa ; diff --git a/basis/math/ranges/ranges-docs.factor b/basis/math/ranges/ranges-docs.factor index 714fc67c9f..f3c65e51a4 100644 --- a/basis/math/ranges/ranges-docs.factor +++ b/basis/math/ranges/ranges-docs.factor @@ -1,21 +1,27 @@ -USING: help.syntax help.markup ; +USING: help.syntax help.markup arrays sequences ; IN: math.ranges ARTICLE: "ranges" "Ranges" - - "A " { $emphasis "range" } " is a virtual sequence with real elements " - "ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } "." - - $nl - - "Creating ranges:" - - { $subsection } - { $subsection [a,b] } - { $subsection (a,b] } - { $subsection [a,b) } - { $subsection (a,b) } - { $subsection [0,b] } - { $subsection [1,b] } - { $subsection [0,b) } ; \ No newline at end of file +"A " { $emphasis "range" } " is a virtual sequence with real number elements " +"ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } "." +$nl +"The class of ranges:" +{ $subsection range } +"Creating ranges with integer end-points. The standard mathematical convention is used, where " { $snippet "(" } " or " { $snippet ")" } " denotes that the end-point itself " { $emphasis "is not" } " part of the range; " { $snippet "[" } " or " { $snippet "]" } " denotes that the end-point " { $emphasis "is" } " part of the range:" +{ $subsection [a,b] } +{ $subsection (a,b] } +{ $subsection [a,b) } +{ $subsection (a,b) } +{ $subsection [0,b] } +{ $subsection [1,b] } +{ $subsection [0,b) } +"Creating general ranges:" +{ $subsection } +"Ranges are most frequently used with sequence combinators as a means of iterating over integers. For example," +{ $code + "3 10 [a,b] [ sqrt ] map" +} +"A range can be converted into a concrete sequence using a word such as " { $link >array } ". In most cases this is unnecessary since ranges implement the sequence protocol already. It is necessary if a mutable sequence is needed, for use with words such as " { $link set-nth } " or " { $link change-each } "." ; + +ABOUT: "ranges" \ No newline at end of file diff --git a/extra/math/combinatorics/combinatorics.factor b/extra/math/combinatorics/combinatorics.factor index f7d7b76fa4..6193edfb91 100644 --- a/extra/math/combinatorics/combinatorics.factor +++ b/extra/math/combinatorics/combinatorics.factor @@ -1,7 +1,7 @@ ! Copyright (c) 2007, 2008 Slava Pestov, Doug Coleman, Aaron Schaefer. ! See http://factorcode.org/license.txt for BSD license. USING: assocs kernel math math.order math.ranges mirrors -namespaces sequences sorting ; +namespaces sequences sequences.lib sorting ; IN: math.combinatorics permutation ; -: reorder ( seq indices -- seq ) - [ [ over nth , ] each drop ] { } make ; - PRIVATE> : factorial ( n -- n! ) @@ -42,7 +39,7 @@ PRIVATE> twiddle [ nPk ] keep factorial / ; : permutation ( n seq -- seq ) - tuck permutation-indices reorder ; + tuck permutation-indices nths ; : all-permutations ( seq -- seq ) [