add trim to contrib/sequences

darcs
erg 2006-10-06 03:45:00 +00:00
parent 85adc51294
commit 7f496c6497
1 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,4 @@
USING: kernel math sequences ; USING: kernel math sequences strings ;
IN: sequences-contrib IN: sequences-contrib
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -15,6 +15,17 @@ IN: sequences-contrib
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: last ( seq -- elt ) dup length 1- swap nth ; : last ( seq -- elt ) [ length 1- ] keep nth ;
: rtrim* ( seq quot -- newseq )
2dup >r last r> call [ >r dup length 1- head-slice r> rtrim* ] [ drop ] if ;
: rtrim ( seq -- newseq ) [ blank? ] rtrim* ;
: ltrim* ( seq quot -- newseq )
2dup >r first r> call [ >r 1 tail-slice r> ltrim* ] [ drop ] if ;
: ltrim ( seq -- newseq ) [ blank? ] ltrim* ;
: trim* ( seq quot -- newseq ) [ ltrim* ] keep rtrim* ;
: trim ( seq -- newseq ) [ blank? ] trim* ;
PROVIDE: contrib/sequences ; PROVIDE: contrib/sequences ;