[REBOL] Re: Newbie query on array indexing
From: tim:johnsons-web at: 22-Nov-2001 9:01
On Thu, Nov 22, 2001 at 10:14:04AM +0000, John R wrote:
> Hi Tim,
>
> Thanks for your examples. Sorry if I was not too clear on last post - I did
> already check out and understand (I hope) all techniques mentioned by Greg
> and Brett and noted the initialisation behaviour with strings, pointers etc.
> IMO it would be nice if "unusual" behaviour like this were highlighted in
> the Rebol documentation.
>
> My outstanding query was trying to assign a value to an array element using
> path syntax with subscript variable. Console session extract below.
>
> Thanks
> John
>
> >> arr-test: array 10 ""
> == ""
> >> loop 10 [append arr-test copy ""]
> == [none none none none none none none none none none "" "" "" "" "" "" ""
> "" "" ""]
>
> >> arr-test/1: "Entry1"
> == ["Entry1" none none none none none none none none none "" "" "" "" "" ""
> "" "" ""
> ""]
> >> arr-test/3: "Entry3"
> == ["Entry1" none "Entry3" none none none none none none none "" "" "" "" ""
> "" "" "
> " "" ""]
> >> n: 3
> == 3
> >> print arr-test/:n
> Entry3
> >> arr-test/:n: "AmendedEntry3"
> ** Syntax Error: Invalid word -- :n:
> ** Near: (line 1) arr-test/:n: "AmendedEntry3"
> >>
>
The short answer is: I believe that you can't do it.
poke arr-test n "Amended Entry3"
; does the trick.
I do agree that it would be a good idea to have a "gotchas" page.
And I do agree that it really makes sense to me to be able to
make assignments directly to path notation.
Many of rebol features are the result of input from mailing list
members.
It is possible that some of the more advanced users or RT members
could point out why this wasn't implemented.
I would point out, that for me, when maintaining code that I haven't
worked with in some time -
poke arr-test ndx "AmendedEntry3"
is more readable and pops out in my conciousness more so than
arr-test/:n: "AmendedEntry3"
but then 'poke has similar connotations in other languages.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com