Paste: .cut - print lines to avoid sidescrolling

Author: rien
Mode: factor
Date: Tue, 11 Oct 2011 06:51:44
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. "

Annotation: using group

Author: Jon
Mode: factor
Date: Wed, 12 Oct 2011 12:12:38
Plain Text |
USE: grouping
: .cut ( str n -- ) group [ . ] each ;

Annotation: indeed, just found that out now

Author: rien
Mode: factor
Date: Sun, 16 Oct 2011 04:44:41
Plain Text |
! Actually I came up with this and just came here to post it again. Very similar to Jon's but I guess because this generates "virtual" sequences that it is faster because it avoids allocation.

USE: grouping
: .cut ( str n -- ) <groups> [ . ] each ;

New Annotation

Summary:
Author:
Mode:
Body: