]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: can't unslice each-index for now
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 26 Jan 2022 17:49:28 +0000 (09:49 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 26 Jan 2022 17:49:28 +0000 (09:49 -0800)
core/sequences/sequences-tests.factor
core/sequences/sequences.factor

index cdb92e6df9ac48326822e983c258f72c05814007..4528ff6d26ae6db207e8c56216792425abb61431 100644 (file)
@@ -19,7 +19,15 @@ IN: sequences.tests
 
 { "cba" } [ "abcdef" 3 head-slice reverse ] unit-test
 
-{ 5040 } [ [ 1 2 3 4 5 6 7 ] 1 [ * ] reduce ] unit-test
+{ 5040 5040 } [
+    [ 1 2 3 4 5 6 7 ] dup rest-slice
+    [ 1 [ * ] reduce ] bi@
+] unit-test
+
+{ 10079 6459 } [
+    [ 1 2 3 4 5 6 7 ] dup rest-slice
+    [ 1 [ [ * ] [ + ] bi* ] reduce-index ] bi@
+] unit-test
 
 { 5040 { 1 1 2 6 24 120 720 } }
 [ { 1 2 3 4 5 6 7 } 1 [ * ] accumulate ] unit-test
@@ -435,4 +443,4 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
 [ { CHAR: l CHAR: l } "o" { } 1surround-as ] unit-test
 
 { "ollo" }
-[ { CHAR: l CHAR: l } "o" "" 1surround-as ] unit-test
\ No newline at end of file
+[ { CHAR: l CHAR: l } "o" "" 1surround-as ] unit-test
index 4878f582a8a2511fe99242d565c89476a46288d7..634d1464166f9b98ab29a27224ffd6e8857e61de 100644 (file)
@@ -410,29 +410,23 @@ PRIVATE>
 : (each-from) ( seq quot i -- i n quot' )
     [ (each) ] dip [ + ] curry 2dip ; inline
 
-: (each-index) ( seq quot -- i n quot' )
-    [ setup-each [ keep ] curry ] dip compose ; inline
-
-: (each-index-from) ( seq quot i -- i n quot' )
-    [ (each-index) ] dip [ + ] curry 2dip ; inline
-
 : (collect) ( quot into -- quot' )
     [ [ keep ] dip set-nth-unsafe ] 2curry ; inline
 
 : collect ( n quot into -- )
     (collect) each-integer ; inline
 
-: setup-map-each ( seq -- n quot )
+: setup-1each ( seq -- n quot )
     [ length check-length ] keep [ nth-unsafe ] curry ; inline
 
-: (map-each) ( seq quot -- n quot' )
-    [ setup-map-each ] dip compose ; inline
+: (1each) ( seq quot -- n quot' )
+    [ setup-1each ] dip compose ; inline
 
-: (map-each-index) ( seq quot -- n quot' )
-    [ setup-map-each [ keep ] curry ] dip compose ; inline
+: (each-index) ( seq quot -- n quot' )
+    [ setup-1each [ keep ] curry ] dip compose ; inline
 
 : map-into ( seq quot into -- )
-    [ (map-each) ] dip collect ; inline
+    [ (1each) ] dip collect ; inline
 
 : 2nth-unsafe ( n seq1 seq2 -- elt1 elt2 )
     [ nth-unsafe ] bi-curry@ bi ; inline
@@ -457,22 +451,18 @@ PRIVATE>
     over [ dupd nth-unsafe ] [ drop f ] if ; inline
 
 : (find) ( seq quot quot' -- i elt )
-    pick [ [ (map-each) ] dip call ] dip finish-find ; inline
+    pick [ [ (1each) ] dip call ] dip finish-find ; inline
 
 : (find-from) ( n seq quot quot' -- i elt )
     [ 2dup bounds-check? ] 2dip
-    [ (find) ] 2curry
-    [ 2drop f f ]
-    if ; inline
+    '[ _ _ (find) ] [ 2drop f f ] if ; inline
 
 : (find-index) ( seq quot quot' -- i elt )
-    pick [ [ (map-each-index) ] dip call ] dip finish-find ; inline
+    pick [ [ (each-index) ] dip call ] dip finish-find ; inline
 
 : (find-index-from) ( n seq quot quot' -- i elt )
     [ 2dup bounds-check? ] 2dip
-    [ (find-index) ] 2curry
-    [ 2drop f f ]
-    if ; inline
+    '[ _ _ (find-index) ] [ 2drop f f ] if ; inline
 
 : (accumulate) ( seq identity quot -- identity seq quot )
     swapd [ keepd ] curry ; inline
@@ -495,7 +485,7 @@ PRIVATE>
     overd [ [ collect ] keep ] new-like ; inline
 
 : map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
-    [ (map-each) ] dip map-integers ; inline
+    [ (1each) ] dip map-integers ; inline
 
 : map ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )
     over map-as ; inline
@@ -637,7 +627,7 @@ PRIVATE>
     [ dup ] swap [ keep ] curry produce nip ; inline
 
 : each-index ( ... seq quot: ( ... elt index -- ... ) -- ... )
-    (each-index) (each-integer) ; inline
+    (each-index) each-integer ; inline
 
 : map-index-as ( ... seq quot: ( ... elt index -- ... newelt ) exemplar -- ... newseq )
     [ dup length <iota> ] 2dip 2map-as ; inline