Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: For loop and dynamic variable

From: cybarite:sympatico:ca at: 18-Mar-2002 8:02

Hi Richard, I saw the solutions based on looping with a variable. They work just fine. But based on your signature line "Share what you know, learn what you don't", you might be interested in these comments: One of the things that I think Carl S was recommending is to not use strings when raw data types work. I also take this to mean that you hold the REBOL types in the collection such as foreach file [%output2.tmp %output2.tmp %output3.tmp] [ then you don't need to name the variables or be concerned with how many there are It is not the one liner that does it all but an approach that uses this might be: foreach file [%output2.tmp %output2.tmp %output3.tmp] [ if exists? file [print ["Deleting " file ] delete file] ] OK .... it can be a one liner: foreach file [%output2.tmp %output2.tmp %output3.tmp] [if exists? file [print ["Deleting " file ] delete file]] but that does not add any value. When the first REBOL book was sold, it came with the Designer's Tip Sheet (Copyright REBOL Technologies All Rights Reserved). Some of the tips in it from Carl are: 1. Forget the past 2. Think simple 4. Data drives it 6. Use words not strings 9. Learn series When I look back at some code that I have done that works, it relied on these design tips to make it workable and maintainable No reply needed.
>>>>>
I have the following code : output1: %output1.tmp output2: %output2.tmp output3: %output3.tmp if exists? output1 [ delete output1 ] if exists? output2 [ delete output2 ] if exists? output3 [ delete output3 ] I want to simplify it like this : for i 1 3 1 [ output(i): %output(i).tmp if exists? output(i) [ delete output(i) ] ] Any ideas ?