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

Setting array variables

 [1/5] from: mike:yaunish:home at: 24-Aug-2000 22:32


I have been using "compose" to set variables within an array, I have the sneaky feeling that there may be easier way.
>>data: [ [ 1 2 3 ] [ 3 4 5 ] ]
== [[1 2 3] [3 4 5]]
>> b: 2
== 2
>> c: 3
== 3
>> new-data: 777
== 777
>> do compose [ (to-set-path reduce [ 'data :a :b ]) new-data ]
== [777 4 5]
>> data
== [[1 2 3] [777 4 5]] Anyone know of an easier way? Mike Yaunish [mike--yaunish--home--com]

 [2/5] from: rryost::home::com at: 25-Aug-2000 11:37


Here's an illustrative console session that addresses your question:
>> dat: array [2 3]
== [[none none none] [none none none]]
>> dat/1: [1 2 3]
== [[1 2 3] [none none none]]
>> dat/2: [3 4 5]
== [[1 2 3] [3 4 5]]
>> change dat/1 777
== [2 3] ; this return allows you to change a number of elements in one statement, but I don't use it here.
>> dat
== [[777 2 3] [3 4 5]]
>> change at dat/1 2 888 ; to change the second element of first row of
array. == [3]
>> dat
== [[777 888 3] [3 4 5]]

 [3/5] from: rryost:home at: 25-Aug-2000 11:47


I've added some more stuff to show how to use a variable for a row number. ----- Original Message ----- From: <[rryost--home--com]> To: <[list--rebol--com]> Sent: Friday, August 25, 2000 11:37 AM Subject: [REBOL] Setting array variables Re:
> Here's an illustrative console session that addresses your question: > >> dat: array [2 3]
== [[none none none] [none none none]]
>> dat/1: [1 2 3]
== [[1 2 3] [none none none]]
>> dat/2: 3 4 5
== 5
>> dat
== [[1 2 3] 3]
>> dat/2: [3 4 5]
== [[1 2 3] [3 4 5]]
>> change dat/1 777
== [2 3]
>> dat
== [[777 2 3] [3 4 5]]
>> change at dat/1 2 888
== [3]
>> dat
== [[777 888 3] [3 4 5]] ; here's how to use a variable for a row number.
>> a: 2
== 2
>> dat/:a
== [3 4 5]
>> change at dat/:a 2 999
== [5]
>> dat
== [[777 888 3] [3 999 5]] Seems easier, no?

 [4/5] from: rryost:home at: 25-Aug-2000 13:33


Oops in my preceding post, I forgot to delete some erroneous stuff. It's separated out below by blank lines. ----- Original Message ----- From: <[rryost--home--com]> To: <[list--rebol--com]> Sent: Friday, August 25, 2000 11:47 AM Subject: [REBOL] Setting array variables Re:(2)
> I've added some more stuff to show how to use a variable for a row number. > ----- Original Message -----
<<quoted lines omitted: 8>>
> >> dat/1: [1 2 3] > == [[1 2 3] [none none none]]
; The following is the wrong way to insert a block!
> >> dat/2: 3 4 5 > == 5 > >> dat > == [[1 2 3] 3]
; Here's the correct way:

 [5/5] from: mike:yaunish:home at: 25-Aug-2000 20:50


At 11:47 AM 8/25/2000 -0700, you wrote: Yes, that is exactly what I was looking for, thanks. I knew there had to be some better way.
>I've added some more stuff to show how to use a variable for a row number. >----- Original Message -----
<<quoted lines omitted: 40>>
>> > >>
Mike Yaunish [mike--yaunish--home--com]

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted