David Ward Lambert wrote (and permitted this to be posted in order to
motivate the use of interval index):
> Dyadic I. is the function one uses to alphabetize a dictionary.
> Dave.
>
> Here's code I wrote a few days ago. (Yes, it can produce output
> longer than COLUMNS. Yes, it suits my purpose.)
>
>
> a=: 'Split a long sentence at word boundaries to fit onto shorter
> lines.'
>
> 'COLUMNS LINES'=: 14 8
> sum =: +/
> prefixes =: \
> size =: #
> words =: adverb def '[: u;.2 ,&'' '''
> box =: <
> take =: {.
>
> COLUMNS*i.LINES
> 0 14 28 42 56 70 84 98
>
> a,'@'
> Split a long sentence at word boundaries to fit onto shorter lines.@
>
> _4 take box words a
> +----+-----+--------+-------+
> |fit |onto |shorter |lines. |
> +----+-----+--------+-------+
>
> size words a
> 6 2 5 9 3 5 11 3 4 5 8 7
>
> sum prefixes size words a
> 6 8 13 22 25 30 41 44 48 53 61 68
>
> NB. assign words to particular rows
> NB. (fourth word belongs on second row)
> (COLUMNS*i.LINES) I. sum prefixes size words a
> 1 1 1 2 2 3 3 4 4 4 5 5
>
> NB. transposing arguments gives the
> NB. index of words to start new row.
> (COLUMNS*i.LINES) I.~ sum prefixes size words a
> 0 3 5 7 10 12 12 12
>
>
> NB. Finally I notice that the size of the words is
> NB. the number of characters in the word. I turn
> NB. this into a hook using copy to tell me which
> NB. characters belong on which line.
>
> (# (COLUMNS*i.LINES) I. sum prefixes) size words a
> 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3
> 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
>
>
> NB. and finally a verb. words appends a space character
> NB. which curtail removes. Then I use the key assignments
> NB. produced by dyadic I.
>
> reform =: (]/.~ }: @ (# (COLUMNS*i.LINES) I. sum prefixes) @
> (size words) )
>
> reform a
> Split a long
> sentence at
> word boundaries
> to fit onto
> shorter lines.
Thank you so much for this response--it was VERY interesting!
Harvey
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm