1

I am quite new to Rexx, really basic stuff here, I want to get the last element of an array quickly.

Open Object Rexx 4.2.0 for Windows:

test.0=2
test.1="foo"
test.2="bar"
say test.[test.0]

==> Output as wanted:

bar

My easy guess is that the Open Object Rexx interpreter is at work. Square brackets can't be used with Rexx on z/OS.

1st stuff that came to my mind (didn't RTFM) :

say test.test.0
say test.(test.0)

==> Output not good:

TEST.TEST.0
    5 *-* say test.(test.0)
Error 16 running Test.REX line 5:  Label not found
Error 16.1:  Label "SYNTAX" not found

Is there other usages of square brackets ? Why coming from C/Java/Python I am going for test.test.0 or test.(test.0) like a dummy ?

Can't find more information about square brackets usage in Rexx than this: #Reginald's tail expression

So under z/OS for now I am stuck with:

temp=test.0
say test.temp
MaesterZ
  • 72
  • 1
  • 9

4 Answers4

3

You have found the answer to your question already.

The only way under mainframe REXX (z/OS, z/VSE, z/VM) is as you coded above:

temp=test.0
say test.temp

The best documentation for understanding what the REXX interpreter is doing can be found in the z/OS TSO/E REXX Reference under Compound Symbols (V2.1 link). It describes why test.test.0 won't work, because of how the interpreter handles the line; in this case, it is looking for a stem test.test.0.

Note that you could code

test.test.0 = 0

and you would have a valid stem test.test.0 (albeit probably useless in most cases).

The next topic in the link discusses stem variables, which also has lots of useful information.

I highly recommend reading both the z/OS TSO/E REXX Reference and the z/OS TSO/E REXX User's Guide (both V2.1 links).


zarchasmpgmr
  • 1,422
  • 10
  • 21
  • 2
    And both of these cases work because, in Rexx, a compound symbol consists of a prefix and a suffix, not indexes or multiple levels. It's a simple variable-expansion-and-concatenation operation. – Ross Patterson Jul 31 '14 at 16:16
2

Other pure (non-Object) Rexx alternatives:

interpret "say test." || test.0

or

say value("test." || test.0)
Ross Patterson
  • 9,527
  • 33
  • 48
0

The default Rexx interpreter on z/OS is Classic Rexx, not OORexx. OORexx has not been ported to z/OS.

cschneid
  • 10,237
  • 1
  • 28
  • 39
  • So what's the quickest way to perform test.[test.0] then ? – MaesterZ Jul 31 '14 at 12:05
  • You've nailed it. It is unfortunate that mainframe Rexx has not been extended like its non-MF counterparts. Of course, the problem would be which fork to follow: OORexx, NetRexx, Regina…they both have their pros and cons. Ob: the REXX Compiler has not been updated since 1999. – zarchasmpgmr Jul 31 '14 at 15:56
  • 1
    Some of us think it is unfortunate that OORexx broke with the Rexx historical path. NetRexx was a little easier to accept, as Mike created it for a specific purpose (close integration with Java). – Ross Patterson Jul 31 '14 at 16:13
0

Bear in mind that (in z/OS, at least) the '.0' variable is not automatically updated. E.g.:

list.1 = 17
list.2 = 12
say 'List.0 is' list.0

Will give 'LIST.0', which is the default value (the variable's name) for an initialised variable.

Steve Ives
  • 7,894
  • 3
  • 24
  • 55
  • No version of Rexx sets `list.0` like that. Some commands (_e.g._, `EXECIO`) do, but it's not a feature of the language. – Ross Patterson Oct 17 '14 at 00:14
  • REXX on z/OS definitely works like that. I know because I've just run that code and got that result. That's why I wrote a 'count' function that returns both the number of variables in a compound variable: say 'There are ' count(list.) ' elements in ''list.''' gives: There are 2 elements in 'list.' As you point out, EXECIO will populate the .0 version with the record count. – Steve Ives Oct 20 '14 at 11:14
  • 1
    No Robin, it's simply an assembler function package. It also works for non-numeric suffixes. I also added 'CONTAINS' (returns TRUE if a compound variable contains a value, 'DROP' (Delete the variable with specified value) & 'FOREACH' (Iterate over all members(>) of a compound variable). – Steve Ives Oct 20 '14 at 13:28
  • LOL - I meant the `list.0` thing, but, touche' :-) – Ross Patterson Oct 20 '14 at 23:18
  • Ah -ok. It's just that I've met people who think that 'list.0' ALWAYS contain the number of elements in the list. I've been trying to make compound variables in z/OS REXX (not ooRexx) more like modern arrays. – Steve Ives Oct 23 '14 at 07:20