]> gitweb.factorcode.org Git - factor.git/commitdiff
make some words not macros
authorDoug Coleman <erg@jobim.local>
Sat, 18 Apr 2009 02:24:36 +0000 (21:24 -0500)
committerDoug Coleman <erg@jobim.local>
Sat, 18 Apr 2009 02:24:36 +0000 (21:24 -0500)
basis/sorting/slots/slots-docs.factor
basis/sorting/slots/slots-tests.factor
basis/sorting/slots/slots.factor

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 ] ;