Hi RChristiansen,

1. first words will fail when words is empty:

>> first []
** Script Error: Out of range or past end.
** Where: first []

To avoid the error use pick words 1 instead:

>> pick [] 1
== none


2.
>in: read %messages.txt
>lines: make block! 10000
>parse in [any [thru newline copy text to newline (append lines text)]]

why don't you use read/lines instead?

lines: read/lines %messages.txt

read/lines returns a block containing each line as a string! You don't need
the additional parsing and you get the same result.

3. 


>       fields: form first lines

Since lines is a block containing strings, first lines will evaluate to a
string and you don't need the additional string conversion provided by form.

4.
>       firstword: form first words

Since words was constructed by appending strings to the block words, first
words will evaluate to a string and you do not need the additional form.


5. 
>       words: []
>       clear words

You could instead write:

words: make block! 0

or

words: copy []

6.
>append out {<HTML><HEAD></HEAD><BODY bgcolor="#FF9999">}

This is the first element you are adding to the block out. Since append is
a convenience which in turn calls insert tail, and therefore more compute
intensive (hardly a worthwhile consideration in your code, just old habit
on my part), and out is empty at this point anyway, you could just as well
just use insert.

You apparently skip the first line that ends with an end of line character
(the "thru newline" part of your rule before you "copy text to newline".
I'm therefore using next read/lines %messages.txt to skip the first line in
messages.txt.

A simpler version of your code would look like this:

out: make string! 100000
insert out {<HTML><HEAD></HEAD><BODY bgcolor="#FF9999">}
words: make block! 0

foreach fields next read/lines %messages.txt [
  clear words
  foreach word parse fields ":" [append words word]
  firstword: pick words 1
]


At 05:43 PM 3/2/00 -0600, you wrote:
>When I run the following script, I get the following error:
>
>** Script Error: Out of range or past end.
>** Where: firstword: form first words
>
>The script runs fine for several loops then quits on this error.  What may
be 
>happening?
>
>
>REBOL []
>
>in: read %messages.txt
>lines: make block! 10000
>parse in [any [thru newline copy text to newline (append lines text)]]
>
>out: make string! 100000
>append out {<HTML><HEAD></HEAD><BODY bgcolor="#FF9999">}
>
>forall lines [
>       fields: form first lines
>
>       words: []
>       clear words
>       foreach word parse fields ":" [append words word]
>
>       firstword: form first words
>]
>
>
>

;- Elan >> [: - )]

Reply via email to