Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loop Control Variable can't be an Element from an Array

137 views
Skip to first unread message

ErichSt

unread,
Apr 17, 2013, 1:18:08 PM4/17/13
to
I noticed that although
do a.1=1 to 3; say a.1; end
works perfectly,

a=.array~new
do a[1]=1 to 3; say a[1]; end

doesn't, as ooRexx doesn't recognize "to" as a reserved keyword here.

Rony

unread,
Apr 17, 2013, 2:13:40 PM4/17/13
to
a[1] is not a variable, but a message term: a~"[]="(1). So the variable is "a" which is a reference
to an array object and not to a number.

If you wish to iterate over an array and show the stored values in ooRexx you could do the following:

do i over a -- loop over array "a", assign value to variable "i"
say i -- show value referenced by the loop variable "i"
end

HTH,

---rony



ErichSt

unread,
Apr 17, 2013, 2:58:12 PM4/17/13
to
> a[1] is not a variable, but a message term: a~"[]="(1).
> So the variable is "a" which is a reference to an array object and not to a number.
At least for me it wasn't obvious at all that this *does* work with a stem, but doesn't with an array


> If you wish to iterate over an array
Well, no, I obviously don't

Glenn Knickerbocker

unread,
Apr 17, 2013, 3:20:38 PM4/17/13
to
On 4/17/2013 2:13 PM, Rony wrote:
> a[1] is not a variable, but a message term: a~"[]="(1). So the
> variable is "a" which is a reference to an array object and not to a
> number.

And the interpreter has no way to know what class it will turn out to
be. It could be some class you've defined where the methods '[]' and
'[]=' don't have such an obvious relationship to each other.

That said, it does already give those names '[]' and '[]=' special
treatment by recognizing them and their arguments without the tilde,
quotes, and parentheses. So I can see arguing that it could "do the
right thing" here and assume the methods will exist, and just let them
behave badly or fail at run time. That would require keeping an
implicit index variable the same way it needs to for "do 3".

It gets more complicated, though, when you consider how you might
manipulate the index variable in a loop:

do i=1 to 3; say i; if skipnext(i) then i=i+1; end

So the implicit index would have to be refreshed from a[1] each time
through the loop. And here's where it gets sticky: After passing the
index value to '[]=' to set it, should it call '[]' again to check the
value to see if it's done, or just assume that the index value it passed
was the one to check?

/* assume? equivalent to: */
index = 1
a[1] = index
do while index <= 3
-- your code here, and then:
index = a[1] + 1
a[1] = index
end

/* or test? equivalent to: */
a[1] = 1
index = a[1] -- might return something different
do while index <= 3
-- your code here, and then:
a[1] = a[1] + 1
index = a[1] -- might return something different
end

I can see arguments for doing it either way.

�R

Glenn Knickerbocker

unread,
Apr 17, 2013, 3:33:52 PM4/17/13
to
On 4/17/2013 2:58 PM, ErichSt wrote:
> At least for me it wasn't obvious at all that this *does* work with a
> stem, but doesn't with an array

Actually, you would run into the same trouble with a stem if you tried
to specify the tail as a literal rather than a symbol:

do a.['literal tail'] = 1 to 3

ŹR

Glenn Knickerbocker

unread,
Apr 17, 2013, 3:44:59 PM4/17/13
to
On 4/17/2013 3:20 PM, I wrote:
> So I can see arguing that it could "do the
> right thing" here and assume the methods will exist, and just let them
> behave badly or fail at run time.

D'oh! I went through all that argument without stopping to realize that
the code actually *runs* and could even be meaningful.

to = 2
a[1] = 1 2 3
do a[1] = 1 to 3; say a[1]; end -- says '1 2 3' once

"a[1] = 1 to 3" is evaluated as an expression and can be either 0 or 1.

That kind of renders all my argument about what it "should" do moot.

�R

Rony

unread,
Apr 17, 2013, 5:05:56 PM4/17/13
to
On 17.04.2013 20:58, ErichSt wrote:
>> a[1] is not a variable, but a message term: a~"[]="(1).
>> So the variable is "a" which is a reference to an array object and not to a number.
> At least for me it wasn't obvious at all that this *does* work with a stem, but doesn't with an array

A stem is a variable which just happens to have a dot in its name (plus each symbol in the tail -
delimited by additional dots - that can be used as variables get substituted by the values they
refer to otherwise the symbol itself - in uppercase - is used as the evaluated value).


>> If you wish to iterate over an array
> Well, no, I obviously don't
That was not as obvious as you think...


---rony





Shmuel Metz

unread,
Apr 19, 2013, 10:10:47 AM4/19/13
to
In <kkn2s8$ca9$1...@speranza.aioe.org>, on 04/17/2013
at 11:05 PM, Rony <rony.fl...@wu-wien.ac.at> said:

>A stem is a variable which just happens to have a dot in its name
>(plus each symbol in the tail - delimited by additional dots -
>that can be used as variables get substituted by the values they
>refer to otherwise the symbol itself - in uppercase - is used as
>the evaluated value).

Not quite: "A stem is a symbol that contains just one period, which is
the last character." You can refer to the stem by explicitly using the
methods of the stem class or by implicitly invoking them using a
compound symbol. It's the compound variable that has a tail, convered
to a list for the implicit invocation of [] and []=.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spam...@library.lspace.org

Rony

unread,
Apr 20, 2013, 7:55:57 AM4/20/13
to
On 19.04.2013 16:10, Shmuel (Seymour J.) Metz wrote:
> In <kkn2s8$ca9$1...@speranza.aioe.org>, on 04/17/2013
> at 11:05 PM, Rony <rony.fl...@wu-wien.ac.at> said:
>
>> A stem is a variable which just happens to have a dot in its name
>> (plus each symbol in the tail - delimited by additional dots -
>> that can be used as variables get substituted by the values they
>> refer to otherwise the symbol itself - in uppercase - is used as
>> the evaluated value).
>
> Not quite: "A stem is a symbol that contains just one period, which is
> the last character." You can refer to the stem by explicitly using the
> methods of the stem class or by implicitly invoking them using a
> compound symbol. It's the compound variable that has a tail, convered
> to a list for the implicit invocation of [] and []=.
>

The ANSI Rexx term for what I dub "stem variable" is "compound variable", which sometimes is also
dubbed "compound symbol" (which is what the ooRexx reference manual uses).

The "stem" is the part that spans the beginning of the symbol up to and including the first dot. the
remainder is dubbed "tail" as you write.

...

The point I tried to make is that a "compound variable" is just a plain variable, hence it can be
used as loop (control) variable in a do or loop keyword instruction, like any other simple
(non-compound) variable in Rexx.

The control variable in a (do) loop needs to evaluate to a number as it gets incremented at the end
of the loop.

The variable the original poster was using as control variable was referring to an array (object)
and not to a number. (He thought instead he was using an item stored in the array as the control
variable.)

---

Ad stems and ooRexx: ooRexx regards stems as (unordered) collections and supplies the AT and PUT
methods, among others. But that is usually not relevant for Rexx programmers who are used to using
compound symbols ("stem variables") as they always did.

---rony

Gerard_Schildberger

unread,
Apr 20, 2013, 11:44:18 AM4/20/13
to
On Friday, April 19, 2013 9:10:47 AM UTC-5, Seymour J. Shmuel Metz wrote:
> on 04/17/2013 at 11:05 PM, Rony said:
>> A stem is a variable which just happens to have a dot in its name
>> (plus each symbol in the tail - delimited by additional dots -
>> that can be used as variables get substituted by the values they
>> refer to otherwise the symbol itself - in uppercase - is used as
>> the evaluated value).

> Not quite: "A stem is a symbol that contains just one period, which is
> the last character." You can refer to the stem by explicitly using the
> methods of the stem class or by implicitly invoking them using a
> compound symbol. It's the compound variable that has a tail, convered
> to a list for the implicit invocation of [] and []=.
> --
> Shmuel (Seymour J.) Metz, SysProg and JOAT

A stem is a symbol that contains just one period,
which is the last character.
It cannot start with a digit or a period.
_______________________________________________ Gerard Schildberger

Shmuel Metz

unread,
Apr 21, 2013, 5:46:06 AM4/21/13
to
In <kktvpn$v7l$1...@speranza.aioe.org>, on 04/20/2013
at 01:55 PM, Rony <rony.fl...@wu-wien.ac.at> said:

>The point I tried to make is that a "compound variable" is just a
>plain variable,

Except that compound symbol isn't a compound variable; even in ANSI
REXX, a compound symbol is a lvalue expression; it evaluates to a
variable reference. In Object Rexx it's a shorthand for a method
invocation.

>The variable the original poster was using as control variable was
>referring to an array (object)

No, it was referring to an element of an array, which is analogous to
referring to an element of a stem object. In both cases there are
invocations of the [] and []= methods.

Rony

unread,
Apr 22, 2013, 11:54:56 AM4/22/13
to
On 21.04.2013 11:46, Shmuel (Seymour J.) Metz wrote:> In <kktvpn$v7l$1...@speranza.aioe.org>, on 04/20/2013
> at 01:55 PM, Rony <rony.fl...@wu-wien.ac.at> said:
>
>> The point I tried to make is that a "compound variable" is just a
>> plain variable,
>
> Except that compound symbol isn't a compound variable; even in ANSI
> REXX, a compound symbol is a lvalue expression; it evaluates to a
> variable reference. In Object Rexx it's a shorthand for a method
> invocation.

When a compound symbol got a value assigned to it, then one calls it a compound variable. Just look
up the ANSI Rexx standard, if in doubt.

Ad Object Rexx and stem variables/compound variables: using the classic Rexx notation deals with
stem variables/compound variables like any other Rexx interpreter. ooRexx allows one to use methods
in addition to interact with stems like "a." (note the trailing dot).

The compound symbol "a.1" got the number "1" assigned to it, such that from this moment on "a.1" is
a compound variable referring to a number, which do/loop mandates.

A compound variable is a variable and can be explicitly used as a control variable.

ANSI Rexx explicitly defines the usage of compound variables as control variables like this:

A.6.4.1 VAR_SYMBOL matching
The control variable from the do_specification and the symbol from the do_ending may both be
compound variables. The matching is


>
>> The variable the original poster was using as control variable was
>> referring to an array (object)
>
> No, it was referring to an element of an array, which is analogous to
> referring to an element of a stem object. In both cases there are
> invocations of the [] and []= methods.

And the variable is "a", which refers to an array object which understands the "[]" and "[]="
messages, because they are implemented for arrays. Hence the variable "a" does not refer to a number
that could be used as a control variable. But this (that a message gets carried out) is not really
significant in the context of the original question of the OP it seems.

(Unlike compound variables there are no definitions anywhere that items pointed by collection
indexes can be used as control variables.)

---rony

Shmuel Metz

unread,
Apr 22, 2013, 9:11:20 PM4/22/13
to
In <kl3mgk$5jb$1...@speranza.aioe.org>, on 04/22/2013
at 05:54 PM, Rony <rony.fl...@wu-wien.ac.at> said:

>When a compound symbol got a value assigned to it, then one calls it
>a compound variable.

No; the *result* of the substiturion is a compound variable.

"The name of the song is called 'Haddock's Eyes'."

Rony

unread,
Apr 23, 2013, 8:54:02 AM4/23/13
to
On 23.04.2013 03:11, Shmuel (Seymour J.) Metz wrote:
> In <kl3mgk$5jb$1...@speranza.aioe.org>, on 04/22/2013
> at 05:54 PM, Rony <rony.fl...@wu-wien.ac.at> said:
>
>> When a compound symbol got a value assigned to it, then one calls it
>> a compound variable.
>
> No; the *result* of the substiturion is a compound variable.
>
> "The name of the song is called 'Haddock's Eyes'."

Using your example: "name" is probably meant to be a variable, if it refers to 'Haddock''s Eyes'.

Or another example: looking at

a=1

Is the symbol "A" a variable or a symbol or both ?
:)

---rony

Duke

unread,
Apr 23, 2013, 6:03:43 PM4/23/13
to
Would asking Mike Cowlishaw directly help?

LesK

unread,
Apr 23, 2013, 6:42:58 PM4/23/13
to
I doubt it. There have already been posts from ooRexx experts to explain
what's happening with the ooRexx coding. The Classic Rexx coding is
_entirely_ different.

--

Les (Change Arabic to Roman to email me)

Rony

unread,
Apr 24, 2013, 8:36:43 AM4/24/13
to
The following program is a Rexx program executed by ooRexx, using the VAR() built-in-function to
test whether a symbol is a variable (refers to a value or not):

say "uninitialized:"
say "a ="a "-> var('a'):" var("a")
say "a.1="a.1 "-> var('a.1'):" var("a.1")
say "---"

a.1="1111"
a="1234"

say "initialized:"
say "a ="a "-> var('a'):" var("a")
say "a.1="a.1 "-> var('a.1'):" var("a.1")
say "---"

drop a.1
drop a
say "uninitialized:"
say "a ="a "-> var('a'):" var("a")
say "a.1="a.1 "-> var('a.1'):" var("a.1")


The above program demonstrates that simple and compound symbols can be used as variables, which one
is able to drop again. Its output is:

a =A -> var('a'): 0
a.1=A.1 -> var('a.1'): 0
---
initialized:
a =1234 -> var('a'): 1
a.1=1111 -> var('a.1'): 1
---
uninitialized:
a =A -> var('a'): 0
a.1=A.1 -> var('a.1'): 0



---rony

Shmuel Metz

unread,
Apr 24, 2013, 9:31:45 AM4/24/13
to
In <kl609m$2fb$1...@speranza.aioe.org>, on 04/23/2013
at 02:54 PM, Rony <rony.fl...@wu-wien.ac.at> said:

>Using your example:

"Haddock's Eye's" is not my example ;-)

>Or another example: looking at
> a=1
>Is the symbol "A" a variable or a symbol or both ?
>:)

"a" is a symbol denoting the variable A. However. in classic Rexx,
"a.b" is a symbol but the variable it denotes depends on the value of
b and can only be determined at run time. I OREXX, of course, "a.b" is
a method invocation.

Glenn Knickerbocker

unread,
Apr 24, 2013, 4:57:46 PM4/24/13
to
On 4/24/2013 8:36 AM, Rony wrote:
> The following program is a Rexx program executed by ooRexx, using the
> VAR() built-in-function to test whether a symbol is a variable
> (refers to a value or not):

Oh, man, all this time I've been sticking with SYMBOL() for this when I
could have been making the test in one step? I'm going to have to dig
into the Builtin Functions section again to see how many more goodies
I've been ignoring!

�R

Glenn Knickerbocker

unread,
Apr 24, 2013, 6:44:56 PM4/24/13
to
On 4/24/2013 9:31 AM, Shmuel (Seymour J.) Metz wrote:
> "a" is a symbol denoting the variable A. However. in classic Rexx,
> "a.b" is a symbol but the variable it denotes depends on the value of
> b and can only be determined at run time. I OREXX, of course, "a.b" is
> a method invocation.

A.b is still a compound symbol, and still the name of a variable.
Referring to that variable creates a method call at run time.

One idea that keeps nagging at me is if, way back when Object Rexx was
created, a[b] had been defined as a new kind of symbol rather than a
message term. That would also have prevented the surprising result of
using it as a clause:

a.[1] = "ECHO Hi there"
a.1 /* says "Hi there" */
a.[1] /* <crickets> */

Naming the referenced variables would get very messy, though, since in
general A could be any term and B could be any list of expressions.

�R

Rony

unread,
Apr 25, 2013, 9:32:24 AM4/25/13
to
There is some "syntax sugar" in ooRexx that plays a role when using the square bracket notations,
which are common in many programming languages when addressing an array.

"Behind the curtain" ooRexx will reformulate a statement like:

a[1]="this is an important entry"

to:

a~"[]="this is an important entry"

Using [] to access an entry in an array, hence:

say a[1]

to:

say a~"[]"(1)

The message form probably looks weird, so thankfully, it is not necessary to use that. But looking
at what happens is interesting as you could take advantage of that for yourself:

- the method "[]=" is a synonym for "PUT"
- the method "[]" is a synonym for "AT"

- this particular ooRexx syntax sugar applies to any class, not only to ooRexx supplied classes,
hence, if you implement the methods "[]=" and "[]" in your own class, then you could write the
non-message form in your programs instead.

---rony


Rony

unread,
Apr 25, 2013, 9:34:57 AM4/25/13
to
Sorry, misformulated in the hurry ...


On 25.04.2013 15:32, Rony wrote:
> On 25.04.2013 00:44, Glenn Knickerbocker wrote:
>> On 4/24/2013 9:31 AM, Shmuel (Seymour J.) Metz wrote:
>>> "a" is a symbol denoting the variable A. However. in classic Rexx,
>>> "a.b" is a symbol but the variable it denotes depends on the value of
>>> b and can only be determined at run time. I OREXX, of course, "a.b" is
>>> a method invocation.
>>
>> A.b is still a compound symbol, and still the name of a variable.
>> Referring to that variable creates a method call at run time.
>>
>> One idea that keeps nagging at me is if, way back when Object Rexx was
>> created, a[b] had been defined as a new kind of symbol rather than a
>> message term. That would also have prevented the surprising result of
>> using it as a clause:
>>
>> a.[1] = "ECHO Hi there"
>> a.1 /* says "Hi there" */
>> a.[1] /* <crickets> */
>>
>> Naming the referenced variables would get very messy, though, since in
>> general A could be any term and B could be any list of expressions.
>
> There is some "syntax sugar" in ooRexx that plays a role when using the square bracket notations,
> which are common in many programming languages when addressing an array.
>
> "Behind the curtain" ooRexx will reformulate a statement like:
>
> a[1]="this is an important entry"
>
> to:
>
> a~"[]="this is an important entry"

the correct reformulation is (the argument to the message must be enclosed in parenthesis, also the
index must be given at which the item should be stored):


a~"[]="("this is an important entry",1)

Glenn Knickerbocker

unread,
Apr 25, 2013, 12:09:48 PM4/25/13
to
On 4/25/2013 9:34 AM, Rony wrote:
>> "Behind the curtain" ooRexx will reformulate a statement like:
>>
>> a[1]="this is an important entry"
>>
>> to:
> a~"[]="("this is an important entry",1)

Right, and that wouldn't change with what I'm suggesting. There would
just be an intermediate step where "a[1]" was recognized as a symbol so
it could be used in all the contexts where symbols are used.

�R

Swifty

unread,
Apr 26, 2013, 4:55:32 AM4/26/13
to
On 24/04/2013 21:57, Glenn Knickerbocker wrote:
> I'm going to have to dig
> into the Builtin Functions section again to see how many more goodies
> I've been ignoring!

My first action was to check MFC's "The REXX Language", where there was
no VAR() found. So not from Classic REXX, probably.

Did VAR() arrive in IBM Object REXX, or oorexx?

A quick search of my home PC came up with rexxref.pdf, (IBM) Object REXX
for Linux, Version 2.2 where VAR() already exists.

--
Steve Swift
http://www.swiftys.org.uk/

LesK

unread,
Apr 26, 2013, 10:47:02 PM4/26/13
to
It's not in my IBM Rexx manual.

Gil Barmwater

unread,
Apr 27, 2013, 7:13:26 AM4/27/13
to
LesK wrote:
> On 4/26/2013 4:55 AM, Swifty wrote:
>
...
>> Did VAR() arrive in IBM Object REXX, or oorexx?
>>
>> A quick search of my home PC came up with rexxref.pdf, (IBM) Object REXX
>> for Linux, Version 2.2 where VAR() already exists.
>>
> It's not in my IBM Rexx manual.
>
IIRC, it was in OS2 Object Rexx first.

LesK

unread,
Apr 27, 2013, 5:00:31 PM4/27/13
to
On 4/27/2013 7:13 AM, Gil Barmwater wrote:
> LesK wrote:
>> On 4/26/2013 4:55 AM, Swifty wrote:
>>
> ....
>>> Did VAR() arrive in IBM Object REXX, or oorexx?
>>>
>>> A quick search of my home PC came up with rexxref.pdf, (IBM) Object REXX
>>> for Linux, Version 2.2 where VAR() already exists.
>>>
>> It's not in my IBM Rexx manual.
>>
> IIRC, it was in OS2 Object Rexx first.

I don't see it in the index of "Object Rexx By Example". I'd have to
hunt for my draft copy of Object Rexx.

Shmuel Metz

unread,
Apr 27, 2013, 10:21:56 PM4/27/13
to
In <kl8jle$v9f$1...@speranza.aioe.org>, on 04/24/2013
at 02:36 PM, Rony <rony.fl...@wu-wien.ac.at> said:

>The above program demonstrates that simple and compound symbols can
>be used as variables, which one is able to drop again.

What is the effect of

I=1
A.I='foo'
I=2
drop A.I

and does that help to illustrate the difference between compound
symbols and compound variables?

Shmuel Metz

unread,
Apr 27, 2013, 10:23:00 PM4/27/13
to
In <B9OdnRok_J31_eXM...@bestweb.net>, on 04/24/2013
at 06:44 PM, Glenn Knickerbocker <No...@bestweb.net> said:

>A.b is still a compound symbol, and still the name of a variable.

It's a compound symbol, but it is *not* the name of a variable. The
variable that it refers to depends on the value of b.

Shmuel Metz

unread,
Apr 27, 2013, 10:24:43 PM4/27/13
to
In <kldfe3$u72$1...@speranza.aioe.org>, on 04/26/2013
at 09:55 AM, Swifty <steve....@gmail.com> said:

>Did VAR() arrive in IBM Object REXX, or oorexx?

Both SYMBOL and VAR were in OREXX for OS/2. What surpised me was

Here are some examples:

/* following: Drop A.3; J=3 */
SYMBOL('J') -> 'VAR'
SYMBOL(J) -> 'LIT' /* has tested "3" */
SYMBOL('a.j') -> 'LIT' /* has tested A.3 */
SYMBOL(2) -> 'LIT' /* a constant symbol */
SYMBOL('*') -> 'BAD' /* not a valid symbol */

I suppose that it makes sense, but I wasn't expecting it.

Rony

unread,
Apr 28, 2013, 11:36:42 AM4/28/13
to
On 28.04.2013 04:21, Shmuel (Seymour J.) Metz wrote:
> In <kl8jle$v9f$1...@speranza.aioe.org>, on 04/24/2013
> at 02:36 PM, Rony <rony.fl...@wu-wien.ac.at> said:
>
>> The above program demonstrates that simple and compound symbols can
>> be used as variables, which one is able to drop again.
>
> What is the effect of
>
> I=1
> A.I='foo'
> I=2
> drop A.I
>
> and does that help to illustrate the difference between compound
> symbols and compound variables?

The point in the original example was that the compound symbol was a.1, hence the tail was a
constant symbol, which will never be replaced by a different value as it cannot be used as a variable.

Your example above uses the symbol "I" as the tail which is *not* a constant symbol, but can be used
as a variable, hence a substitution may take place, if "I" was a variable itself, otherwise "I"
would be used.

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]).

---rony





Glenn Knickerbocker

unread,
Apr 28, 2013, 1:22:26 PM4/28/13
to
On Sat, 27 Apr 2013 22:23:00 -0400, Shmuel wrote:
>Glenn Knickerbocker <No...@bestweb.net> said:
>>A.b is still a compound symbol, and still the name of a variable.
>It's a compound symbol, but it is *not* the name of a variable.

The doc is pretty consistent in treating a symbol and its evaluated name
(after translation and substitution) as the same thing. The descriptions
of SYMBOL() and VAR() both talk about whether the symbol "is the name of
a variable," not whether it evaluates to the name of a variable.

�R http://users.bestweb.net/~notr/kartuli "That looks like a
harpsichord on the stage, but the program says it's a continuo!"

Shmuel Metz

unread,
Apr 30, 2013, 11:37:47 PM4/30/13
to
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.

Rony

unread,
May 1, 2013, 5:35:14 AM5/1/13
to
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






Shmuel Metz

unread,
Apr 30, 2013, 11:50:45 PM4/30/13
to
In <09mqn8pgt37ppfb2p...@4ax.com>, on 04/28/2013
at 01:22 PM, Glenn Knickerbocker <No...@bestweb.net> said:

>The doc is pretty consistent in treating a symbol and its evaluated
>name (after translation and substitution) as the same thing. The
>descriptions of SYMBOL() and VAR() both talk about whether the
>symbol "is the name of a variable," not whether it evaluates to
>the name of a variable.

"returns the state of the symbol named by name" would appear to
distinguish the two.

Shmuel Metz

unread,
May 1, 2013, 2:16:15 PM5/1/13
to
In <klqnjr$qo7$1...@speranza.aioe.org>, on 05/01/2013
at 11:35 AM, Rony <rony.fl...@wu-wien.ac.at> said:

>The variable's name is "a" in this case

Yes, "a" is a variable, but "a[1]" is not. As you note, the latter is
an invocation of the []= or [] method.
0 new messages