|
Pages: [1]
|
 |
|
Author
|
Topic: Behavior of 'set word' statemet (Read 667 times)
|
|
jfdutcher
|
The code below works fine and creates a block of 299 smaller blocks, each with (4) items in it; can't argue with success. i would like to understand why the statement: " sortblock: [] " doesn't re-initialize the block on each pass through the loop......I thought such a statement did just that...but it doesn't..as the block continues to grow. repeat i 299 rec1: read-record port 2690 i sortblock: [] y: 1 regnbr: substr rec1 y + 3 4 lname: substr rec1 y + 7 15 fname: substr rec1 y + 22 15 minit: substr rec1 y + 37 1 repend/only sortblock [lname fname minit regnbr] ]
*** read-record and substr are functions in the script
|
|
|
|
|
Logged
|
|
|
|
|
jfdutcher
|
I think I am indebted to the "codeconcious" website for the answer to this...it goes as follows: (I substituted the word 'loop' for the word 'function' in the explanation below on their site in the paragraphs below, believing that a 'loop' or a 'function' apparently behave the same way in this issue). ****************************************************** "The incongruity between our expectation and the actual results comes down to the line of the loop where "sortBlock" is set to an empty string.
The answer is this. The empty string is a value which is created *once* during load of the block that represents the body of the loop. The loop is based on a copy of this block and therefore gets this empty string when it is created.
When the loop is run, the empty string is no longer empty. This no longer emtpy string referred to by the word "sortBlock" is stored within the body of the block. Thus the definition of the loop while still exactly the same appears to be changing each run. "
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
Pages: [1]
|
|
|
 |