Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Behavior of 'set word' statemet
Pages: [1] Print
Author Topic: Behavior of 'set word' statemet  (Read 668 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Behavior of 'set word' statemet
« on: April 19, 2006, 11:51:31 AM »

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.

Code:
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
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Re: Behavior of 'set word' statemet
« Reply #1 on: April 19, 2006, 12:54:07 PM »

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
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Re: Behavior of 'set word' statemet
« Reply #2 on: April 20, 2006, 01:17:39 AM »

You got it.

To get round this, just use...

sortblock: copy []

Off topic:  My email alert to this post sent me here...

http://reboltalk.com/forum/index.php?topic=295.new#new

but all I get is an error there.  And I note this thread is # 296...

http://reboltalk.com/forum/index.php/topic,296.0.html

Will complain more loudly if I find this is happening all the time...
Logged

- Carl Read
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Behavior of 'set word' statemet
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 10:29:39 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2315 Posts in 597 Topics by 4205 Members
Latest Member: TimTearton

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc