Paste: .cut - print lines to avoid sidescrolling

Author: rien
Mode: factor
Date: Tue, 11 Oct 2011 06:50:07
Plain Text |
! is there a better way to write .cut ?

: (.cut) ( vec str n -- vec str n )
    2dup swap length <
    [ [ cut ] keep
      [ [| v x xs | x v push v xs ] call ] dip (.cut) ] [ ] if ;

: .cut ( str n -- )
    0 <vector> -rot (.cut) drop swap [ push ] keep [ . ] each ;

! (I was using V{ } instead of 0 <vector> and had a nasty surprise after running the following example twice - now everything works fine, though :) )

! example usage:

! ( scratchpad )
"this is a very long string and it's highly annoying to read a long string by having to scroll sideways. " dup [ append ] curry 2 swap times 60 .cut
"this is a very long string and it's highly annoying to read "

"a long string by having to scroll sideways. this is a very l"
"ong string and it's highly annoying to read a long string by"
" having to scroll sideways. this is a very long string and i"
"t's highly annoying to read a long string by having to scrol"
"l sideways. "

New Annotation

Summary:
Author:
Mode:
Body: