From 223a2e494569e1712329539438fcd3a53fe7e225 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 25 Aug 2022 18:02:47 -0400 Subject: [PATCH] sequences: fix from word `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 | 2 +- core/sequences/sequences.factor | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basis/combinators/smart/smart.factor b/basis/combinators/smart/smart.factor index 28a09eb2bc..8b597a58b4 100644 --- a/basis/combinators/smart/smart.factor +++ b/basis/combinators/smart/smart.factor @@ -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 ) diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 4cebf8e263..d2d6c2640f 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -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