]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Tue, 12 Feb 2008 01:33:49 +0000 (17:33 -0800)
committerJoe Groff <arcata@gmail.com>
Tue, 12 Feb 2008 01:33:49 +0000 (17:33 -0800)
Conflicts:

extra/sequences/lib/lib.factor

1  2 
extra/sequences/lib/lib.factor

index b761bf957fe4e78e1f6022e9e6d9bca5111ca18d,1d95f9fdf6cda7fbfc283edaf8d54859ba0c5f1f..1beec90b7515b7f7bfdc38acc75331681255ca47
@@@ -1,8 -1,45 +1,45 @@@
+ ! Copyright (C) 2007 Slava Pestov, Chris Double, Doug Coleman,
+ !                    Eduardo Cavazos, Daniel Ehrenberg.
+ ! See http://factorcode.org/license.txt for BSD license.
  USING: combinators.lib kernel sequences math namespaces assocs 
  random sequences.private shuffle math.functions mirrors
- arrays math.parser math.private sorting strings ascii ;
 -arrays math.parser sorting strings ascii macros ;
++arrays math.parser math.private sorting strings ascii macros ;
  IN: sequences.lib
  
+ : each-withn ( seq quot n -- ) nwith each ; inline
+ : each-with ( seq quot -- ) with each ; inline
+ : each-with2 ( obj obj list quot -- ) 2 each-withn ; inline
+ : map-withn ( seq quot n -- newseq ) nwith map ; inline
+ : map-with ( seq quot -- ) with map ; inline
+ : map-with2 ( obj obj list quot -- newseq ) 2 map-withn ; inline
+ MACRO: nfirst ( n -- )
+     [ [ swap nth ] curry [ keep ] curry ] map concat [ drop ] compose ;
+ : prepare-index ( seq quot -- seq n quot )
+     >r dup length r> ; inline
+ : each-index ( seq quot -- )
+     #! quot: ( elt index -- )
+     prepare-index 2each ; inline
+ : map-index ( seq quot -- )
+     #! quot: ( elt index -- obj )
+     prepare-index 2map ; inline
+ ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ : sigma ( seq quot -- n )
+     [ rot slip + ] curry 0 swap reduce ; inline
+ : count ( seq quot -- n )
+     [ 1 0 ? ] compose sigma ; inline
  ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  
  : map-reduce ( seq map-quot reduce-quot -- result )
@@@ -149,18 -190,7 +190,18 @@@ PRIVATE
  ! List the positions of obj in seq
  
  : indices ( seq obj -- seq )
 -    >r dup length swap r>
 -    [ = [ ] [ drop f ] if ] curry
 -    2map
 -    [ ] subset ;
 +  >r dup length swap r>
 +  [ = [ ] [ drop f ] if ] curry
 +  2map
 +  [ ] subset ;
 +
 +<PRIVATE
 +: (attempt-each-integer) ( i n quot -- result )
 +    [
 +        iterate-step roll
 +        [ 3nip ] [ iterate-next (attempt-each-integer) ] if*
 +    ] [ 3drop f ] if-iterate? ; inline
 +PRIVATE>
 +
 +: attempt-each ( seq quot -- result )
-     (each) iterate-prep (attempt-each-integer) ; inline
++    (each) iterate-prep (attempt-each-integer) ; inline