]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 18 Apr 2009 02:38:59 +0000 (21:38 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 18 Apr 2009 02:38:59 +0000 (21:38 -0500)
basis/generalizations/generalizations-docs.factor
basis/generalizations/generalizations.factor
basis/sorting/slots/slots-docs.factor
basis/sorting/slots/slots-tests.factor
basis/sorting/slots/slots.factor
core/slots/slots.factor

index 2088e468c64593800b8d869e335f6b618ceb6bfa..36715111940242937ab1e43d6976993a4151f139 100644 (file)
@@ -272,8 +272,8 @@ HELP: nweave
 \r
 HELP: n*quot\r
 { $values\r
-     { "n" integer } { "seq" sequence }\r
-     { "seq'" sequence }\r
+     { "n" integer } { "quot" quotation }\r
+     { "quot'" quotation }\r
 }\r
 { $examples\r
     { $example "USING: generalizations prettyprint math ;"\r
index 0aa042d4f2e7056159d3d1775c8fd31853fc5808..637f958eb5a436d57972f6afecdad21eba45efdc 100644 (file)
@@ -7,7 +7,7 @@ IN: generalizations
 
 <<
 
-: n*quot ( n seq -- seq' ) <repetition> concat >quotation ;
+: n*quot ( n quot -- seq' ) <repetition> concat >quotation ;
 
 : repeat ( n obj quot -- ) swapd times ; inline
 
@@ -94,4 +94,4 @@ MACRO: nweave ( n -- )
 : nappend-as ( n exemplar -- seq )
     [ narray concat ] dip like ; inline
 
-: nappend ( n -- seq ) narray concat ; inline
\ No newline at end of file
+: nappend ( n -- seq ) narray concat ; inline
index cc89d497e78202b7349e121e214dd3ee4e255042..b427cf2956b45b227dd4a998c22dc7efdf0c8c6a 100644 (file)
@@ -14,7 +14,7 @@ HELP: compare-slots
 HELP: sort-by-slots
 { $values
      { "seq" sequence } { "sort-specs" "a sequence of accessors ending with a comparator" }
-     { "sortedseq" sequence }
+     { "seq'" sequence }
 }
 { $description "Sorts a sequence of tuples by the sort-specs in " { $snippet "sort-spec" } ". A sort-spec is a sequence of slot accessors ending in a comparator." }
 { $examples
@@ -42,7 +42,7 @@ HELP: split-by-slots
 HELP: sort-by
 { $values
     { "seq" sequence } { "sort-seq" "a sequence of comparators" }
-    { "sortedseq" sequence }
+    { "seq'" sequence }
 }
 { $description "Sorts a sequence by comparing elements by comparators, using subsequent comparators when there is a tie." } ;
 
index 83900461c3dfbe0255c209edc71399b981ae3e30..e31b9be3598b1237414b40d2ae7417714e45a52f 100644 (file)
@@ -159,3 +159,15 @@ TUPLE: tuple2 d ;
     { { 3 2 1 } { 1 2 3 } { 1 3 2 } { 1 } }
     { length-test<=> <=> } sort-by
 ] unit-test
+
+[ { { 0 1 } { 1 2 } { 1 1 } { 3 2 } } ]
+[
+    { { 3 2 } { 1 2 } { 0 1 } { 1 1 } }
+    { length-test<=> <=> } sort-keys-by
+] unit-test
+
+[ { { 0 1 } { 1 1 } { 3 2 } { 1 2 } } ]
+[
+    { { 3 2 } { 1 2 } { 0 1 } { 1 1 } }
+    { length-test<=> <=> } sort-values-by
+] unit-test
index efec960c2749855d67a2a4ef86bc5b3e4c7b6d8c..9a0455c3a73147533c4c26ad0d8171b17460af21 100644 (file)
@@ -8,12 +8,13 @@ IN: sorting.slots
 <PRIVATE
 
 : short-circuit-comparator ( obj1 obj2 word --  comparator/? )
-    execute dup +eq+ eq? [ drop f ] when ; inline
+    execute( obj1 obj2 -- obj3 )
+    dup +eq+ eq? [ drop f ] when ; inline
 
 : slot-comparator ( seq -- quot )
     [
         but-last-slice
-        [ '[ [ _ execute ] bi@ ] ] map concat
+        [ '[ [ _ execute( tuple -- value ) ] bi@ ] ] map concat
     ] [
         peek
         '[ @ _ short-circuit-comparator ]
@@ -25,21 +26,22 @@ MACRO: compare-slots ( sort-specs -- <=> )
     #! sort-spec: { accessors comparator }
     [ slot-comparator ] map '[ _ 2|| +eq+ or ] ;
 
-MACRO: sort-by-slots ( sort-specs -- quot )
-    '[ [ _ compare-slots ] sort ] ;
+: sort-by-slots ( seq sort-specs -- seq' )
+    '[ _ compare-slots ] sort ;
 
 MACRO: compare-seq ( seq -- quot )
     [ '[ _ short-circuit-comparator ] ] map '[ _ 2|| +eq+ or ] ;
 
-MACRO: sort-by ( sort-seq -- quot )
-    '[ [ _ compare-seq ] sort ] ;
+: sort-by ( seq sort-seq -- seq' )
+    '[ _ compare-seq ] sort ;
 
-MACRO: sort-keys-by ( sort-seq -- quot )
+: sort-keys-by ( seq sort-seq -- seq' )
     '[ [ first ] bi@ _ compare-seq ] sort ;
 
-MACRO: sort-values-by ( sort-seq -- quot )
+: sort-values-by ( seq sort-seq -- seq' )
     '[ [ second ] bi@ _ compare-seq ] sort ;
 
 MACRO: split-by-slots ( accessor-seqs -- quot )
-    [ [ '[ [ _ execute ] bi@ ] ] map concat [ = ] compose ] map
+    [ [ '[ [ _ execute( tuple -- value ) ] bi@ ] ] map concat
+    [ = ] compose ] map
     '[ [ _ 2&& ] slice monotonic-slice ] ;
index a353f5094736da78b96f07ec3cdd928870bbb0c8..63c0319c1ce429251258b010169ccd47d83f941c 100755 (executable)
@@ -222,7 +222,7 @@ M: slot-spec make-slot
     [ make-slot ] map ;
 
 : finalize-slots ( specs base -- specs )
-    over length [ + ] with map [ >>offset ] 2map ;
+    over length iota [ + ] with map [ >>offset ] 2map ;
 
 : slot-named ( name specs -- spec/f )
     [ name>> = ] with find nip ;