]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: fix from word
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Aug 2022 22:02:47 +0000 (18:02 -0400)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Feb 2023 23:11:03 +0000 (17:11 -0600)
`from` can go last or second to last, exemplar goes last

the natural place for the `from` is at the bottom of the stack,
but requiring the callers to do this is more stack shuffling
at every call vs just shuffling it in the word. also you have to
know how deep to -rot the `from` so it's best to leave it to the
combinators

basis/combinators/smart/smart.factor
core/sequences/sequences.factor

index 28a09eb2bcd25c6c40974a0e413522929a193b67..8b597a58b4b76c23e5247862084153fd3b016c4d 100644 (file)
@@ -158,7 +158,7 @@ MACRO: smart-2map-reduce ( 2map-reduce-quots -- quot )
     [ keys ] [ [ [ ] concat-as ] [ ] map-as ] bi dup length dup '[
         [ [ first ] bi@ _ 2cleave ] 2keep
         [ @ _ [ cleave-curry ] [ cleave-curry ] bi _ spread* ]
-        1 -roll 2each-from
+        1 2each-from
     ] ;
 
 : smart-loop ( ..a quot: ( ..a -- ..b ? ) -- ..b )
index 4cebf8e263c201d0c2694eff4e17aa77f8a37b89..d2d6c2640fc83481a4104f031eb935b0b275812d 100644 (file)
@@ -602,8 +602,8 @@ PRIVATE>
 : 2each ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... )
     2length-operator each-integer ; inline
 
-: 2each-from ( ... from seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... )
-    2length-operator each-integer-from ; inline
+: 2each-from ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) from -- ... )
+    -roll 2length-operator each-integer-from ; inline
 
 : 2reduce ( ... seq1 seq2 identity quot: ( ... prev elt1 elt2 -- ... next ) -- ... result )
     -rotd 2each ; inline
@@ -1161,7 +1161,7 @@ PRIVATE>
 
 : 2map-reduce ( ..a seq1 seq2 map-quot: ( ..a elt1 elt2 -- ..a intermediate ) reduce-quot: ( ..a prev intermediate -- ..a next ) -- ..a result )
     [ [ [ [ first ] bi@ ] 2keep ] dip [ 2dip ] keep ] dip
-    '[ rot _ dip swap @ ] 1 -roll 2each-from ; inline
+    '[ rot _ dip swap @ ] 1 2each-from ; inline
 
 <PRIVATE