For loop and dynamic variable
[1/12] from: richard::coffre::francetelecom::com at: 18-Apr-2002 12:01
Hi
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 ?
TIA
Richard Coffre
France Telecom Orbiscom
T=E9l. : 01 47 61 46 28
Share what you know, learn what you don't
[2/12] from: sunandadh:aol at: 18-Apr-2002 6:21
Richard:
> for i 1 3 1 [
> output(i): %output(i).tmp
> if exists? output(i) [ delete output(i) ]
> ]
>
> Any ideas
I'd write:
for i 1 3 1 [
file-name: to-file join "output" [i ".tmp"]
if all [exists? file-name
not dir? file-name ][
delete file-name
] ;; if
] ;; for
(I've added a check that the resultant name isn't a directory (folder) just
because I'd do that in my own code. May be you don't need it in your
application).
Sunanda.
[3/12] from: rebol665:ifrance at: 18-Apr-2002 13:01
Bonjour,
Nos amis anglais appellent ça un ""oneliner" :
for i 1 3 1 [ if exists? f: to-file rejoin ["output" i ".tmp"][delete f]]
Patrick
----- Original Message -----
From: "COFFRE Richard FTO" <[richard--coffre--francetelecom--com]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, April 18, 2002 12:01 PM
Subject: [REBOL] For loop and dynamic variable
Hi
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 ?
TIA
Richard Coffre
France Telecom Orbiscom
Tél. : 01 47 61 46 28
Share what you know, learn what you don't
[4/12] from: richard:coffre:francetelecom at: 18-Apr-2002 13:32
Thanks you
-----Message d'origine-----
De : [SunandaDH--aol--com] [mailto:[SunandaDH--aol--com]]
Envoy=E9 : jeudi 18 avril 2002 12:22
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: For loop and dynamic variable
Richard:
> for i 1 3 1 [
> output(i): %output(i).tmp
> if exists? output(i) [ delete output(i) ]
> ]
>
> Any ideas
I'd write:
for i 1 3 1 [
file-name: to-file join "output" [i ".tmp"]
if all [exists? file-name
not dir? file-name ][
delete file-name
] ;; if
] ;; for
(I've added a check that the resultant name isn't a directory (folder) just
because I'd do that in my own code. May be you don't need it in your
application).
Sunanda.
[5/12] from: petr:krenzelok:trz:cz at: 18-Apr-2002 13:10
COFFRE Richard FTO wrote:
>Hi
>I have the following code :
<<quoted lines omitted: 9>>
> if exists? output(i) [ delete output(i) ]
>]
for i 1 3 1 [
set to-word join 'output i f: join %output reduce [i ".tmp"]
if exists? f [delete f]
]
... but that's not probably the cleanes solution anyway.... :-)
for i 1 3 1 [if exists? file: join %output reduce [i ".tmp"] [delete file] ]
.... a shorter one :-)
-pekr-
[6/12] from: richard:coffre:francetelecom at: 18-Apr-2002 13:43
Good, thanks Petr
-----Message d'origine-----
De : Petr Krenzelok [mailto:[petr--krenzelok--trz--cz]]
Envoy=E9 : jeudi 18 avril 2002 13:10
=C0 : [rebol-list--rebol--com]
Objet : [REBOL] Re: For loop and dynamic variable
COFFRE Richard FTO wrote:
>Hi
>I have the following code :
<<quoted lines omitted: 9>>
> if exists? output(i) [ delete output(i) ]
>]
for i 1 3 1 [
set to-word join 'output i f: join %output reduce [i ".tmp"]
if exists? f [delete f]
]
... but that's not probably the cleanes solution anyway.... :-)
for i 1 3 1 [if exists? file: join %output reduce [i ".tmp"] [delete file] ]
.... a shorter one :-)
-pekr-
[7/12] 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 ?
[8/12] from: ronald:free at: 18-Apr-2002 14:02
Bonjour COFFRE,
Thursday, April 18, 2002, 12:01:12 PM, vous avez écrit:
CRF> Hi
CRF> I have the following code :
CRF> output1: %output1.tmp
CRF> output2: %output2.tmp
CRF> output3: %output3.tmp
CRF> if exists? output1 [ delete output1 ]
CRF> if exists? output2 [ delete output2 ]
CRF> if exists? output3 [ delete output3 ]
CRF> I want to simplify it like this :
CRF> for i 1 3 1 [
CRF> output(i): %output(i).tmp
CRF> if exists? output(i) [ delete output(i) ]
CRF> ]
CRF> Any ideas ?
CRF> TIA
CRF> Richard Coffre
CRF> France Telecom Orbiscom
CRF> Tél. : 01 47 61 46 28
CRF> "Share what you know, learn what you don't"
CRF> --
CRF> To unsubscribe from this list, please send an email to
CRF> [rebol-request--rebol--com] with "unsubscribe" in the
CRF> subject, without the quotes.
This should make the job :
num: [1 2 3]
foreach ind num [if exists? todelete: to-file rejoin ["output" ind ".tmp"][delete todelete]]
--
Best Regards,
Ronald
[9/12] from: joel:neely:fedex at: 18-Apr-2002 9:47
Hi, Richard,
Just for the sake of variety...
COFFRE Richard FTO wrote:
> >
> >I want to simplify it like this :
<<quoted lines omitted: 7>>
> if exists? file: join %output reduce [i ".tmp"] [delete file]
> ]
Instead of generating the file names, and then testing for their
existence (and status as plain file, not directory), you could
read the current directory and test whether each of its contents
matches the pattern you are looking for:
digits: charset "0123456789"
foreach item read %./ [
if parse/all item [
"output" some digits ".tmp"
][
print [item dir? item]
]
]
This produces output similar to the following:
output1.tmp false
output2.tmp false
output4.tmp false
and, of course, you can do something else with the ones that pass
your criteria.
-jn-
[10/12] from: joel:neely:fedex at: 18-Apr-2002 10:52
Hi, Richard,
COFFRE Richard FTO wrote:
> >
> >I want to simplify it like this :
<<quoted lines omitted: 7>>
> if exists? file: join %output reduce [i ".tmp"] [delete file]
> ]
Instead of generating the file names, and then testing for their
existence (and status as plain file, not directory), you could
read the current directory and test whether each of its contents
matches the pattern you are looking for:
digits: charset "0123456789"
foreach item read %./ [
if parse/all item [
"output" some digits ".tmp"
][
print [item dir? item]
]
]
This produces output similar to the following:
output1.tmp false
output2.tmp false
output4.tmp false
and, of course, you can do something else with the ones that pass
your criteria.
-jn-
[11/12] from: greggirwin:mindspring at: 18-Apr-2002 10:25
Hi Richard,
How about:
outputs: [%output1.tmp %output3.tmp %output3.tmp]
foreach file outputs [
if exists? file [
delete file
]
]
Then you can also access them as outputs/1, etc. if you want.
--Gregg
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 ?
TIA
Richard Coffre
France Telecom Orbiscom
Tél. : 01 47 61 46 28
Share what you know, learn what you don't
[12/12] from: riusa:email:it at: 19-Apr-2002 9:56
Hi,
Based on your original request...
>Hi
>I have the following code :
<<quoted lines omitted: 4>>
>if exists? output2 [ delete output2 ]
>if exists? output3 [ delete output3 ]
you can try the following line (dynamic variables...):
output1: %output1.tmp
delete get 'output1
Using get is useful since you can "extract" an Obj reference from a
variable.
bye!
--Alessandro--
--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f
Sponsor:
Vorresti trasformare il tuo salotto in un cinema?
Amplificatore Yamaha RX V520: stupendo. E' in offerta su Bow.it!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=402&d=19-4
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted