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

[array] Some other questions

 [1/5] from: antonr::iinet::net::au at: 22-Nov-2003 19:40


Watch out though, each item in chickenfarm is the same chicken object:
> >> chicken: make object! [ > [ tasty: "wings"
<<quoted lines omitted: 10>>
> t... > Andrew J Martin
Try this: chickenfarm/1/tasty: "drumsticks" ; change first object in the block chickenfarm == [ make object! [ tasty: "drumsticks" ] make object! [ tasty: "drumsticks" ] make object! [... Oh no! They have all changed because they are in fact, all the same. same? chickenfarm/1 chickenfarm/2 ;== true I recommend doing this instead: chickenfarm: copy [] ; make a new block loop 10 [append chickenfarm make chicken []] Now they are all cloned from the original chicken. Anton.

 [2/5] from: joel:neely:fedex at: 22-Nov-2003 7:29


Hi, Andrew, A J Martin wrote:
> Anton wrote: > >>Watch out though, each item in chickenfarm is the same chicken object: > > Yes! You've found a bug in 'array! >
It's not a bug, since AFAIK there's no published specification that says ARRAY should behave any differently than it does. We've seen this issue before, in connection with other reference types, as in
>> foo: "Hi!"
== "Hi!"
>> gorp: array/initial 10 foo
== ["Hi!" "Hi!" "Hi!" "Hi!" "Hi!" "Hi!" "Hi!" "Hi!" "Hi!" "Hi!"]
>> foo/2: #"a"
== "Ha!"
>> gorp
== ["Ha!" "Ha!" "Ha!" "Ha!" "Ha!" "Ha!" "Ha!" "Ha!" "Ha!" "Ha!"] Given the available documentation for ARRAY:
>> ? array
USAGE: ARRAY size /initial value DESCRIPTION: Makes and initializes a series of a given size. ARRAY is a function value. ARGUMENTS: size -- Size or block of sizes for each dimension (Type: integer block) REFINEMENTS: /initial -- Specify an initial value for all elements value -- Initial value (Type: any) it is consistent that the (single!) initial value is uses for all elements. -jn-

 [3/5] from: AJMartin:orcon at: 24-Dec-2003 22:49


Hi, Joel! Joel wrote:
> Given the available documentation for ARRAY: > ... > /initial -- Specify an initial value for all elements > it is consistent that the (single!) initial value is uses for all
elements. Hmmm, at the moment, I can't see a good use for an array that has multiple references to the one series or object. :-/ The /Initial refinement seems, to me, to indicate a initial value for each element, implying that each element in the result is distinct. I believe that 'array is more useful to most people when each value is a unique value, like:
>> x: array/initial 10 123
== [123 123 123 123 123 123 123 123 123 123]
>> x/1: x/1 + 456
== [579 123 123 123 123 123 123 123 123 123]
>> x: array/initial 10 "abc"
== ["abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc"]
>> insert tail x/1 "def"
== ""
>> x
== ["abcdef" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc"] And if I do need a block with multiple references to the one series or object, I can very easily write:
>> x: head insert/dup [] "abc" 10
== ["abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc" "abc"]
>> insert tail x/1 "def"
== ""
>> x
== ["abcdef" "abcdef" "abcdef" "abcdef" "abcdef" "abcdef" "abcdef" "abcdef" abcdef "abcd ef"] Just my opinion. :) Andrew J Martin Speaking in tongues and performing miracles. ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/

 [4/5] from: joel:neely:fedex at: 22-Nov-2003 16:08


Hi, Andrew, A J Martin wrote:
> Hi, Joel! >> /initial -- Specify an initial value for all elements
<<quoted lines omitted: 4>>
> to me, to indicate a initial value for each element, implying that each > element in the result is distinct.
I guess we're just differing over the interpretation of the words here. I read the phrases "a value for all elements" and "a value for each element" as slightly different (but see below).
> I believe that 'array is more useful to > most people when each value is a unique value, like: >
When dealing with reference values I certainly agree that it would be more useful if /INITIAL gave a *spec* to be used to construct an initial value for each element. My quibble was only with the notion of calling the present behavior a bug, instead of saying that it would have been more useful if ARRAY worked in the way that you (and I) would have expected. I'm just being an old grouch on this point because I've recently been bitten again by a subtlety that isn't documented anywhere that I could find, so I had to resort to "particle physics" just to figure out what the interpreter was doing (and have to hope that it won't change in a future release). It's just my old build-to-spec temperament, chanting: If there ain't no spec, there ain't no bugs! ;-) -jn-

 [5/5] from: greggirwin:mindspring at: 22-Nov-2003 18:10


Hi Andrew, AJM> Hmmm, at the moment, I can't see a good use for an array that has multiple AJM> references to the one series or object. Handy for providing a default value without consuming lots of memory doing so? Just thinking out loud. I don't use array too much (except when I started with REBOL IIRC). -- Gregg

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