]> gitweb.factorcode.org Git - factor.git/commitdiff
assocs: move with-assoc back to assocs
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 6 Feb 2023 00:36:16 +0000 (18:36 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Feb 2023 23:11:03 +0000 (17:11 -0600)
There are two uses of `curry [ swap ] prepose`. One is to swap the arguments
from assoc-each etc from ( key value ) to ( value key ). The other use in
sequences is for hiding the top stack element from the quotation.

core/assocs/assocs.factor
core/sequences/sequences.factor

index 2ae679cba2c084171070264ffe802af9093684cd..92019367a2f22914baf02a2197d62aa2a9fc013e 100644 (file)
@@ -125,6 +125,9 @@ PRIVATE>
 : of ( assoc key -- value/f )
     swap at ; inline
 
+: with-assoc ( assoc quot: ( ..a value key assoc -- ..b ) -- quot: ( ..a key value -- ..b ) )
+    curry [ swap ] prepose ; inline
+
 M: assoc assoc-clone-like
     [ dup assoc-size ] dip new-assoc
     [ [ set-at ] with-assoc assoc-each ] keep ; inline
index 352ba460073202d8c6b176b3072027ce2c978ae6..7761b49bb7115459ec32d3e9a7d544c33a09f9cb 100644 (file)
@@ -724,11 +724,8 @@ PRIVATE>
 : last-index-from ( obj i seq -- n )
     rot [ = ] curry find-last-from drop ;
 
-: with-assoc ( assoc quot: ( ..a value key assoc -- ..b ) -- quot: ( ..a key value -- ..b ) )
-    curry [ swap ] prepose ; inline
-
 : indices ( obj seq -- indices )
-    swap [ = ] with-assoc V{ } clone [
+    swap [ = ] curry [ swap ] prepose V{ } clone [
         [ push ] curry [ [ drop ] if ] curry compose each-index
     ] keep ;
 
@@ -1179,7 +1176,7 @@ M: repetition sum [ elt>> ] [ length>> ] bi * ; inline
 : supremum ( seq -- elt ) [ ] [ max ] map-reduce ;
 
 : map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n )
-    [ 0 ] 2dip [ dip + ] with-assoc each ; inline
+    [ 0 ] 2dip [ dip + ] curry [ swap ] prepose each ; inline
 
 : count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )
     [ 1 0 ? ] compose map-sum ; inline