Rebol Talk Forum  |  REBOL Discussions  |  REBOL Core  |  Topic: Using 'variable' names in series 'paths'
Pages: [1] Print
Author Topic: Using 'variable' names in series 'paths'  (Read 862 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Using 'variable' names in series 'paths'
« on: February 15, 2007, 09:56:32 PM »

The piece of code below wants to use a changing variable value to loop over a block....Rebol returns an error stating that a varibale name is not allowed in 'paths' referencing blocks.  Surely this cannot be the case....as looping logic 'requires' variables of changing values....what needs to be done to make this work ?

Rebol[Title: "sortRegnbrs"]

vetsdb: make block! load %/c/vetssrc/dietsys/rebdsysmst.txt

size: length? vetsdb

for y 2 size 2 [
   sortBlock: []
        regnbr: vetsdb/y/1       
   lname: vetsdb/y/2       
   fname: vetsdb/y/3     
   minit: vetsdb/y/4
   repend/only sortBlock [lname fname mold minit regnbr] 
]
   
data-block: sort sortBlock
Logged
Philippe
Newbie
*
Offline Offline

Posts: 34


View Profile WWW
Re: Using 'variable' names in series 'paths'
« Reply #1 on: February 16, 2007, 12:16:45 AM »

Hello,

First, it depends on the contents of your rebdsysmst.txt file. Maybe you can use (if it's OK with the structure of your datas) : read/lines wich returns directly a block (block!) with all lines. First line = blk/1, second line = blk/2, etc.
For iteration, "foreach" is often quicker than "for". And why you initialize your sortBlock at any interation ?
If you use anyway the "for" form, your variable can change like (note the ":" before the y variable) :

Quote
list: [ blk1 [inf1 inf2] blk2 [info1 info2] blk3 [ii1 ii2]]

result: copy []

for y 2 (length? list) 2 [
regnbr: list/:y/1
append result regnbr
]
probe sort result

; and same with foreach
result2: copy []
foreach [data1 data2 ] list [
append result2 data2/1
]
probe sort result2

It's a way. Adapt it to your case.

===Philippe
Logged

===Philippe
PeterWood
Newbie
*
Offline Offline

Posts: 34


View Profile
Re: Using 'variable' names in series 'paths'
« Reply #2 on: February 16, 2007, 09:35:59 PM »

Using foreach as Phillipe suggested is the answer to your problem.

If I remember correctly from earlier posts, vetsdb is a block of data with each "record" consisting of regnbr [vetsdata].

So I would write something like this;

sortblock: copy []
foreach [regnbr vetsdata] vetsvb [
   sortnbr: regnbr       
   lname: vetsdata/1       
   fname: vetsdata/2     
   minit: vetsdata/3
   repend/only sortBlock [lname fname mold minit sortnbr]
]
   
data-block: sort sortBlock

Peter
Logged
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL Core  |  Topic: Using 'variable' names in series 'paths'
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 07:21:58 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2311 Posts in 595 Topics by 4140 Members
Latest Member: Houolid

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

RT design by Defiant Pc