On 01.05.2013 05:37, Shmuel (Seymour J.) Metz wrote:
> In <kljfm6$k6a$
1...@speranza.aioe.org>, on 04/28/2013
> at 05:36 PM, Rony <
rony.fl...@wu-wien.ac.at> said:
>
>> The point I have tried to make all along this thread has been, that
>> compound variables are not comparable to (simple) variables that
>> refer to non-numbers as was assumed and shown in the original example
>> (i.e. expecting that a.1 would be equivalent to a[1]).
>
> Well, a[1] does not exist in classic Rexx and is not a variable in
> OREXX.
The variable's name is "a" in this case, a simple symbol, which refers to an array, hence it is used
as a variable:
a=.array~new /* create an array and assign its reference to variable "a" */
say "var('a'):" var("a")
say "---"
a~put("Hi, Shmuel",1) /* add an entry at index 1 */
a~"[]="("Hi, Seymour",2) /* add an entry at index 2 */
a[3]="Hi, J." /* add an entry at index 3, syntax sugar */
do i=1 to a~items /* loop over the items in the array */
say a[i] "==" a~"[]"(i) "==" a~at(i)
end
say "---"
say "or an alternative to iterate over items of a collection:"
do item over a
say item
end
Running the above yields:
var('a'): 1
---
Hi, Shmuel == Hi, Shmuel == Hi, Shmuel
Hi, Seymour == Hi, Seymour == Hi, Seymour
Hi, J. == Hi, J. == Hi, J.
---
or an alternative to iterate over items of a collection:
Hi, Shmuel
Hi, Seymour
Hi, J.
So the variable is named "a", a simple symbol. "a" refers to an ooRexx array. The array methods
"PUT", "[]=" are synonyms as are the array methods "AT" and "[]".
The ooRexx syntax sugar comes into play with translating
a[i]=RHS to a~"[]="(RHS, i)
and
a[i] to a~"[]"(i)
This is an implementation detail in ooRexx that can be usually neglected, except for discussions
like this, where it becomes important to see what ooRexx does "behind the curtain" when resolving
syntax sugar.
---rony