I just ain't gettin' it! :)
[1/14] from: edanaii::cox::net at: 18-Dec-2002 14:42
OK,
This is something in REBOL I just haven't figured out yet.
How do update a value in the middle of a series?
If I have an array of x: [ 1 2 3 4 ], how do I update it to be x: [ 1 2
5 4 ]. I do not want to change any other value and I want to do it based
on Index.
I can do this: x/3: 5. But I want to do this dynamically and can't
figure out how to use "Change" (if that is the right function) to do it
within a program.
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[2/14] from: sunandadh:aol at: 18-Dec-2002 17:41
Ed:
> If I have an array of x: [ 1 2 3 4 ], how do I update it to be x: [ 1 2
> 5 4 ]. I do not want to change any other value and I want to do it based
> on Index.
One way is 'poke (just like good old fashioned Basic):
x: [ 1 2 3 4 ]
index: 3
;; replace a value
poke x index 5
== [1 2 5 4]
;; do something to a value:
poke x index x/:index * 2
== [1 2 10 4]
Sunanda.
[3/14] from: philb:upnaway at: 19-Dec-2002 7:21
Hi Ed,
I'm sure than in Rebol there are many ways of doing this and I am sure there are more
elegant ways of doing this, but you could try :
a: [1 2 3 4]
b: skip a 2
remove b
insert b 5
probe a
Typing at the console gives
>> a: [1 2 3 4]
== [1 2 3 4]
>> b: skip a 2
== [3 4]
>> remove b
== [4]
>> insert b 5
== [4]
>> probe a
[1 2 5 4]
== [1 2 5 4]
Of course you culd wrap this up in a function taking a series, index & value as parameters
Cheers Phil
=== Original Message ===
OK,
This is something in REBOL I just haven't figured out yet.
How do update a value in the middle of a series?
If I have an array of x: [ 1 2 3 4 ], how do I update it to be x: [ 1 2
5 4 ]. I do not want to change any other value and I want to do it based
on Index.
I can do this: x/3: 5. But I want to do this dynamically and can't
figure out how to use "Change" (if that is the right function) to do it
within a program.
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[4/14] from: al:bri:xtra at: 19-Dec-2002 13:41
Here's another way, using 'change and 'at:
>> x: [ 1 2 3 4 ]
== [1 2 3 4]
>> index: 3
== 3
>> change at x index 5
== [4]
>> x
== [1 2 5 4]
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[5/14] from: ammon:addept:ws at: 18-Dec-2002 17:05
Hi,
Try something like:
>> a: [1 2 3 4]
== [1 2 3 4]
>> change/part find a 3 5 1
== [4]
>> a
== [1 2 5 4]
>> ? change
USAGE:
CHANGE series value /part range /only /dup count
DESCRIPTION:
Changes a value in a series and returns the series after the change.
CHANGE is an action value.
ARGUMENTS:
series -- Series at point to change (Type: series port)
value -- The new value (Type: any)
REFINEMENTS:
/part -- Limits the amount to change to a given length or position.
range -- (Type: number series port)
/only -- Changes a series as a series.
/dup -- Duplicates the change a specified number of times.
count -- (Type: number)
HTH
Ammon Johnson --- CIO
Addept ------------------ (www.addept.ws)
435-616-2322 -------- (ammon at addept.ws)
[6/14] from: anton:lexicon at: 19-Dec-2002 11:18
Ed, try this:
>> x: [1 2 3 4 5]
== [1 2 3 4 5]
>> change at x 3 5
== [4 5]
>> x
== [1 2 5 4 5]
Anton.
[7/14] from: tomc:darkwing:uoregon at: 18-Dec-2002 16:52
Hi Ed,
my favorite is question your data, I mean code -- no data um errrr
>> x: [1 2 3 4 5]
== [1 2 3 4 5]
>> y: 3
== 3
>> z: 9
== 9
>> do rejoin['x"/"(y)": " (z)]
== [1 2 9 4 5]
On Wed, 18 Dec 2002, Ed Dana wrote:
[8/14] from: edanaii:cox at: 19-Dec-2002 7:53
[SunandaDH--aol--com] wrote:
>Ed:
>>If I have an array of x: [ 1 2 3 4 ], how do I update it to be x: [ 1 2
<<quoted lines omitted: 12>>
>== [1 2 10 4]
>Sunanda.
That's the ticket!
Exactly what I was looking for.
Thanks, Sunanda. :)
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[9/14] from: edanaii:cox at: 19-Dec-2002 7:56
Ammon Johnson wrote:
>Hi,
> Try something like:
<<quoted lines omitted: 13>>
>>>
>>>
Yes, but 'change changes based on a value, doesn't it? That's where I got confused in
trying to use it. Played with /part, but just wasn't getting it right.
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[10/14] from: greggirwin:mindspring at: 19-Dec-2002 9:56
Hi Ed,
ED> Yes, but 'change changes based on a value, doesn't it? That's where
ED> I got confused in trying to use it. Played with /part, but just
ED> wasn't getting it right.
No, CHANGE changes a value at a given position in a series, or
multiple values if you use /PART. You use AT to get the series at
the position you want to change.
-- Gregg
[11/14] from: edanaii:cox at: 19-Dec-2002 12:29
Gregg Irwin wrote:
>No, CHANGE changes a value at a given position in a series, or
>multiple values if you use /PART. You use AT to get the series at
>the position you want to change.
>
Yea, I finally realized why I got confused.
>> x: [ 1 2 3 4 5 ]
== [1 2 3 4 5]
>> Change at x 3 5
== [4 5]
Issuing Change appeared to cause a partial result set [ 4 5 ] to be
returned.
It wasn't until after I did the following that I realized my mistake.
>> x
== [1 2 5 4 5]
--
Sincerely, | The problems of two little people don't amount to
Ed Dana | a hill of beans in this crazy mixed-up world! But
Software Developer | this is OUR hill, and these are OUR beans!
1Ghz Athlon Amiga | -- Naked Gun via Casablanca.
[12/14] from: carl:cybercraft at: 20-Dec-2002 12:42
On 20-Dec-02, Ed Dana wrote:
> [SunandaDH--aol--com] wrote:
>> One way is 'poke (just like good old fashioned Basic):
<<quoted lines omitted: 9>>
> Exactly what I was looking for.
> Thanks, Sunanda. :)
Note however that the opposite isn't peek, but...
>> pick [a b c d e] 3
== c
(:
--
Carl Read
[13/14] from: cal:prolific at: 18-Dec-2002 15:31
you can do it with change, but it's probably easier to do what you described
using 'POKE
>> help poke
USAGE:
POKE value index data
DESCRIPTION:
Returns value after changing its data at the given index. (See
manual)
POKE is an action value.
ARGUMENTS:
value -- (Type: series money date time object port tuple)
index -- (Type: number logic)
data -- new value (Type: any)
>> x: [ 1 2 3 4 ]
== [1 2 3 4]
>> n: 3
== 3
>> poke x n 5
== [1 2 5 4]
[14/14] from: rebol-list2:seznam:cz at: 20-Dec-2002 12:45
Hello Ed,
Wednesday, December 18, 2002, 10:42:10 PM, you wrote:
ED> OK,
ED> This is something in REBOL I just haven't figured out yet.
ED> How do update a value in the middle of a series?
ED> If I have an array of x: [ 1 2 3 4 ], how do I update it to be x: [ 1 2
ED> 5 4 ]. I do not want to change any other value and I want to do it based
ED> on Index.
ED> I can do this: x/3: 5. But I want to do this dynamically and can't
ED> figure out how to use "Change" (if that is the right function) to do it
ED> within a program.
This is one of the things in Rebol that could be better... I like
the way how it's in other languages:
x = new Array(1,2,3,4)
x[2] = 5
as this is quite powerful (and more readable) in the more dimensional arrays:
x[2][1] = 5
y[0]["fruit"] = "lemons";
=( Oliva David )=======================( [oliva--david--seznam--cz] )==
=( Earth/Europe/Czech_Republic/Brno )=============================
=( coords: [lat: 49.22 long: 16.67] )=============================
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted