2drop
] [
over previous get conjoin
- dup slip
+ [ call ] keep
[ nip (closure) ] curry assoc-each
] if ; inline recursive
: (read) ( n quot -- n string )
over 0 <string> [
[
- slip over
- [ swapd set-nth-unsafe f ] [ 3drop t ] if
- ] 2curry find-integer
+ over [ swapd set-nth-unsafe f ] [ 3drop t ] if
+ ] curry compose find-integer
] keep ; inline
: finish-read ( n string -- string/f )
-! Copyright (C) 2004, 2008 Slava Pestov.
+! Copyright (C) 2004, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel.private slots.private math.private
classes.tuple.private ;
! Loops
: loop ( pred: ( -- ? ) -- )
- dup slip swap [ loop ] [ drop ] if ; inline recursive
+ [ call ] keep [ loop ] curry when ; inline recursive
: do ( pred body tail -- pred body tail )
over 3dip ; inline
: iterate-step ( i n quot -- i n quot )
#! Apply quot to i, keep i and quot, hide n.
- swap [ 2dup 2slip ] dip swap ; inline
+ [ nip call ] 3keep ; inline
: iterate-next ( i n quot -- i' n quot ) [ 1+ ] 2dip ; inline
over 0 < [
2drop f
] [
- 2dup 2slip rot [
+ [ call ] 2keep rot [
drop
] [
[ 1- ] dip find-last-integer
over map-into ; inline
: accumulate ( seq identity quot -- final newseq )
- swapd [ pick slip ] curry map ; inline
+ swapd [ [ call ] [ 2drop ] 3bi ] curry map ; inline
: 2each ( seq1 seq2 quot -- )
(2each) each-integer ; inline
[ but-last-slice ] [ peek ] bi ; inline
: <flat-slice> ( seq -- slice )
- dup slice? [ { } like ] when 0 over length rot <slice> ;
+ dup slice? [ { } like ] when
+ [ drop 0 ] [ length ] [ ] tri <slice> ;
inline
<PRIVATE
: supremum ( seq -- n ) [ ] [ max ] map-reduce ;
-: sigma ( seq quot -- n ) [ 0 ] 2dip [ rot slip + ] curry each ; inline
+: sigma ( seq quot -- n )
+ [ 0 ] 2dip [ dip + ] curry [ swap ] prepose each ; inline
: count ( seq quot -- n ) [ 1 0 ? ] compose sigma ; inline