]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 5 Jan 2009 23:33:12 +0000 (17:33 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 5 Jan 2009 23:33:12 +0000 (17:33 -0600)
.gitignore
basis/compiler/utilities/utilities.factor
core/sequences/sequences-tests.factor
core/sequences/sequences.factor
license.txt

index f4334f37278ce8cfb2aa838fc2eda20635f93e9b..a7cbeeeef3ff73e95b6411eb112505e050b18843 100644 (file)
@@ -21,3 +21,4 @@ logs
 work
 build-support/wordsize
 *.bak
+.#*
index 1f488b3dde81384ae35c4d15ac1e2fb62a45f8bd..e8082edb68daf6247787d16f65aea7db59e08db2 100644 (file)
@@ -21,11 +21,3 @@ IN: compiler.utilities
 : map-flat ( seq quot -- seq' ) [ each ] flattening ; inline
 
 : 2map-flat ( seq quot -- seq' ) [ 2each ] flattening ; inline
-
-: (3each) ( seq1 seq2 seq3 quot -- n quot' )
-    [ [ [ length ] tri@ min min ] 3keep ] dip
-    '[ [ _ nth-unsafe ] [ _ nth-unsafe ] [ _ nth-unsafe ] tri @ ] ; inline
-
-: 3each ( seq1 seq2 seq3 quot -- seq ) (3each) each ; inline
-
-: 3map ( seq1 seq2 seq3 quot -- seq ) (3each) map ; inline
index dcca525e2bbf1626ac037a1e2d347778e672adaf..80352faf728a0b49d872809dedb370a6e2d56a9f 100644 (file)
@@ -32,8 +32,8 @@ IN: sequences.tests
 [ 4 CHAR: o ]
 [ 3 "hello world" "aeiou" [ member? ] curry find-from ] unit-test
 
-[ f         ] [ 3 [ ]     member? ] unit-test
-[ f         ] [ 3 [ 1 2 ] member? ] unit-test
+[ f ] [ 3 [ ]     member? ] unit-test
+[ f ] [ 3 [ 1 2 ] member? ] unit-test
 [ t ] [ 1 [ 1 2 ] member? ] unit-test
 [ t ] [ 2 [ 1 2 ] member? ] unit-test
 
@@ -55,6 +55,11 @@ IN: sequences.tests
 
 [ [ 3 ] ] [ [ 1 2 3 ] 2 [ swap < ] curry filter ] unit-test
 
+[ V{ 1 2 3 } ] [ V{ 1 4 2 5 3 6 } clone [ [ 4 < ] filter-here ] keep ] unit-test
+[ V{ 4 2 6 } ] [ V{ 1 4 2 5 3 6 } clone [ [ 2 mod 0 = ] filter-here ] keep ] unit-test
+
+[ V{ 3 } ] [ V{ 1 2 3 } clone [ 2 [ swap < ] curry filter-here ] keep ] unit-test
+
 [ "hello world how are you" ]
 [ { "hello" "world" "how" "are" "you" } " " join ]
 unit-test
@@ -261,3 +266,14 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
 
 [ "a,b" ] [ "a" "b" "," glue ] unit-test
 [ "(abc)" ] [ "abc" "(" ")" surround ] unit-test
+
+[ "HELLO" ] [
+    "HELLO" { -1 -1 -1 -1 -1 } { 2 2 2 2 2 2 }
+    [ * 2 + + ] 3map
+] unit-test
+
+{ 3 1 } [ [ 3array ] 3map ] must-infer-as
+
+{ 3 0 } [ [ 3drop ] 3each ] must-infer-as
+
+[ V{ 0 3 } ] [ "A" { "A" "B" "C" "A" "D" } indices ] unit-test
\ No newline at end of file
index 40a8892e8b2c19bc7241f3c9fbb9c9847cd4047b..557a52c482d4acc5f25e640a181554cf69ef1bb0 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2008 Slava Pestov, Daniel Ehrenberg.
+! Copyright (C) 2005, 2009 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel kernel.private slots.private math
 math.private math.order ;
@@ -117,9 +117,9 @@ INSTANCE: integer immutable-sequence
     [ tuck [ nth-unsafe ] 2bi@ ]
     [ tuck [ set-nth-unsafe ] 2bi@ ] 3bi ; inline
 
-: (head) ( seq n -- from to seq ) 0 spin ; inline
+: (head) ( seq n -- from to seq ) [ 0 ] 2dip swap ; inline
 
-: (tail) ( seq n -- from to seq ) over length rot ; inline
+: (tail) ( seq n -- from to seq ) swap [ length ] keep ; inline
 
 : from-end ( seq n -- seq n' ) [ dup length ] dip - ; inline
 
@@ -352,6 +352,10 @@ PRIVATE>
 : 2map-into ( seq1 seq2 quot into -- newseq )
     [ (2each) ] dip collect ; inline
 
+: (3each) ( seq1 seq2 seq3 quot -- n quot' )
+    [ [ [ length ] tri@ min min ] 3keep ] dip
+    [ [ [ [ nth-unsafe ] curry ] tri@ tri ] 3curry ] dip compose ; inline
+
 : finish-find ( i seq -- i elt )
     over [ dupd nth-unsafe ] [ drop f ] if ; inline
 
@@ -419,6 +423,12 @@ PRIVATE>
 : 2all? ( seq1 seq2 quot -- ? )
     (2each) all-integers? ; inline
 
+: 3each ( seq1 seq2 seq3 quot -- )
+    (3each) each ; inline
+
+: 3map ( seq1 seq2 seq3 quot -- newseq )
+    (3each) map ; inline
+
 : find-from ( n seq quot -- i elt )
     [ (find-integer) ] (find-from) ; inline
 
@@ -494,10 +504,12 @@ PRIVATE>
 : last-index-from ( obj i seq -- n )
     rot [ = ] curry find-last-from drop ;
 
+: (indices) ( elt i obj accum -- )
+    [ swap [ = ] dip ] dip [ push ] 2curry when ; inline
+
 : indices ( obj seq -- indices )
-    V{ } clone spin
-    [ rot = [ over push ] [ drop ] if ]
-    curry each-index ;
+    swap V{ } clone
+    [ [ (indices) ] 2curry each-index ] keep ;
 
 : nths ( indices seq -- seq' )
     [ nth ] curry map ;
@@ -566,7 +578,7 @@ M: slice equal? over slice? [ sequence= ] [ 2drop f ] if ;
 PRIVATE>
 
 : filter-here ( seq quot -- )
-    0 0 roll (filter-here) ; inline
+    swap [ 0 0 ] dip (filter-here) ; inline
 
 : delete ( elt seq -- )
     [ = not ] with filter-here ;
@@ -828,7 +840,7 @@ PRIVATE>
 
 : supremum ( seq -- n ) dup first [ max ] reduce ;
 
-: sigma ( seq quot -- n ) 0 -rot [ rot slip + ] curry each ; inline
+: sigma ( seq quot -- n ) [ 0 ] 2dip [ rot slip + ] curry each ; inline
 
 : count ( seq quot -- n ) [ 1 0 ? ] compose sigma ; inline
 
index 768c13c54997f830fe99ae76d648b438adc7c872..8f4f53585aa3b6fbde6e36b231930115b8b0a344 100644 (file)
@@ -1,4 +1,4 @@
-Copyright (C) 2003, 2008 Slava Pestov and friends.
+Copyright (C) 2003, 2009 Slava Pestov and friends.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met: