I'm missing something fundamental ...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

I'm missing something fundamental ...

Chip Davis-2
Okay guys, this is probably an easy one for you.  I'm afraid I'm missing
something fundamental with regard to indexed strings and until clauses.
I've reduced my program to the the following fragment in which the loop
never terminates:

trace results
parse source . . me .
file = BufferedReader(FileReader(me))
rec = ''
loop i = 1 until rec[i] = null
  rec[i] = file.readLine()
end i
say rec[i-1]

The salient portion of the trace shows that rec[i] never matches null:

 6 *=*   rec[i] = file.readLine()
   >>> "7"
   >v> rec "end i"
 5 *=* loop i = 1 until rec[i] = null
   >>> "7"
   >>> "0"
   >v> i "8"
 6 *=*   rec[i] = file.readLine()
   >>> "8"
   >v> rec [null]
 5 *=* loop i = 1 until rec[i] = null
   >>> "8"
   >>> "0"
   >v> i "9"

Falling back to a working example, I tried reading the line into a simple
variable, then assigning that variable to the indexed variable:

trace results
parse source . . me .
file = BufferedReader(FileReader(me))
rec = ''
loop i = 1 until line = null
  line = file.readLine()
  rec[i] = line
end i
say rec[i-1]

.. which gave me the following NetRexx error:

  5 +++ loop i = 1 until line = null
    +++                  ^^^^
    +++ Error: Unknown variable

.. which I fixed by initializing 'line':

trace results
parse source . . me .
file = BufferedReader(FileReader(me))
rec = ''
line = ''
loop i = 1 until line = null
  line = file.readLine()
  rec[i] = line
end i
say rec[i-1]

.. which works, but leaves me with two questions:

1. Why did the until clause comparison fail with an indexed variable?

2. Why must I initialize an until clause variable that is assigned in the
body of the loop?

I'm running the OS/2 JDK 1.1.1 with NetRexx 1.113, if it matters.

-Chip Davis-      Aresti Systems   Member of: Rexx Language Association
[hidden email]   P.O.Box 13306               ANSI Rexx Standard Committee
919.303.3306      RTP NC 27709-3306           TeamOS/2 & Thoroughly Warped!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>