Replace, select, find and stuff
[1/3] from: hallvard::ystad::oops-as::no at: 30-Apr-2005 17:48
Hi list
I need to replace a value in a hash!, and find I cannot use 'replace.
The hash is like this:
>> a: make hash! [1 "A" 2 "B" 3 "C" 4 "D"]
== make hash! [1 "A" 2 "B" 3 "C" 4 "D"]
Now let's say I have
>> e: "E"
== "E"
and that I want to replace "C" with "E" in 'a.
I'd like to do something like this:
replace/select a 3 e
but instead, I have to do two statements, like this:
>> remove next find a 3
== make hash! [4 "D"]
>> insert next find a 3 e
== make hash! [4 "D"]
Then we get
>> a
== make hash! [1 "A" 2 "B" 3 "E" 4 "D"]
But maybe someone knows how to achieve this in a simpler manner?
HY
[2/3] from: gabriele:colellachiara at: 30-Apr-2005 17:50
Hi Hallvard,
On Saturday, April 30, 2005, 5:48:09 PM, you wrote:
HY> and that I want to replace "C" with "E" in 'a.
replace a "C" "E"
?
But I guess you want to change the value that follows a given
value (using the HASH! with key-value pairs):
key: 3
value: "E"
change next find a key value
If the key could be absent, you'll need to check the result of
FIND.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[3/3] from: hallvard::ystad::oops-as::no at: 30-Apr-2005 17:59
Dixit Gabriele Santilli (17.50 30.04.2005):
>Hi Hallvard,
>On Saturday, April 30, 2005, 5:48:09 PM, you wrote:
>HY> and that I want to replace "C" with "E" in 'a.
> replace a "C" "E"
>?
I don't know that "C" is indeed "C", I only know it is preceeded by 3, as you suggest
underneath.
>But I guess you want to change the value that follows a given
>value (using the HASH! with key-value pairs):
> key: 3
> value: "E"
> change next find a key value
'change! Of course! Thanks, Gabriele.
Maybe 'change and 'replace could have a /select refinement...? (Just thinking aloud).
HY