[REBOL] Re: Newbie query on array indexing
From: tim:johnsons-web at: 21-Nov-2001 19:25
Hi John
> Greg, Brett,
>
> Thanks for your suggestions and advice. While Rebol is certainly powerful it
> seems to have plenty of quirks waiting to trip the unwary - maybe it gets
> better the more you get into it!
I will guarantee that it does get better....
Here's a couple of observations
All programming languages have "hidden quirks".
Having written in about 10 of them, I find I create my own
hidden quirks
by assuming the logic of the language rathering
than taking the time to understand it as well as I should.
I find that I understand rebol better if I think of it as a
C
program (which I believe the binary IS), but don't think
of the syntax as anything but possibilities....
> I still could not get the following type of array element assignment
> reference to work (this was my original approach):-
> ; define array
> example-array: array/initial 10 ""
> ; define index
> idx: 3
> ; try to set element at offset defined by index value
> example-array/:n : "data"
Why not try the following exercise, John..
>> test: make block! 25
== []
; there are maybe better ways to do this, but this creates unique "pointers"
; into 'test
>> loop 25[append test copy ""]
; looks the same, but each element is different
; reference Brett's email on this subject
== ["" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]
>> append test/20 "line 20"
== "line 20"
>> test
== ["" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "line 20" "" "" "" "" ""]
>> poke test 15 "this is element 15"
== ["" "" "" "" "" "" "" "" "" "" "" "" "" "" "this is element 15" "" "" "" "" "line
20" "" "" "" "" ""]
> Different syntax required?
Here's another exercise: Prepare to be edified! :>)
>> test: make block! 25
== []
>> loop 25[append test copy ""]
>> same? test/2 test/22
== false ; COMPARE THIS TO THE NEXT EXAMPLE
>> arrcodes: array/initial 25 ""
== ["" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]
>> same? arrcodes/2 arrcodes/22
== true ;VERY IMPORTANT DISTINCTION
> Thanks
> John
One method that works well in "harnessing" the power of this mailing list
is to either:
copy and paste a contiguous interpreter session into your email.
OR
Send a complete script.
HTH
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com