Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Anton Monroe

Pages: [1]
1
In Rexx a variable can contain the name of another variable. The documentation I have seen gives examples, but doesn't explain why you would want to do that.

Say you want to keep a llst of names and their attributes. In another language you would create an array of names and attributes and search it for the record you want. You could do that in Rexx, but there is an easier way. You can create a separate variable for each name and then simply refer to that variable, without needing to search through a list. Here is an example:
Code: [Select]
/**/
   /*  create some variables  */
   Data = 'Crocus 5 blue Tulip 8 red Daffodil 12 yellow'
   NameList = ''
   do while Data \= ''
      parse var Data !Name Ht Clr Data
      NameList = NameList !Name
      call value !Name'.Height', Ht
      call value !Name'.Color', Clr
   end

   do w = 1 to words(NameList)
      !Name = word(NameList, w)
      say !Name':'
      say '   Height:' value(!Name'.Height')
      say '   Color: ' value(!Name'.Color')
   end w
   exit

What this does is create stem variables called CROCUS.HEIGHT, CROCUS.COLOR,
TULIP.HEIGHT, TULIP.COLOR, etc. There are some things to note:
* I make a practice of using '!' in the !Name variable to
  indicate that it stands for another variable. It makes it easier
  for me to understand what is going on.
* you must keep a separate list of the names. That 'NameList' variable is the
  only record of what variables you have created.
* use "call Value" to assign the variables. The Value function resolves the
  string to a variable name, uppercases the name, and then assigns a value to
  it. Likewise use Value() when reading the variable.

But, you ask, what if I want to share those variables with a procedure?
How can I expose the list of variables if I don't know what variables
will exist at the time the script is executed?

You can do that by packaging everything in a stem variable. So the variables
will be called FLOWER.CROCUS.HEIGHT, etc. Then expose the name of the stem.
Like this:

Code: [Select]
/**/
   Data = 'Crocus 5 blue Tulip 8 red Daffodil 12 yellow'
   Flower.NameList = ''
   do while Data \= ''
      parse var Data !Name Ht Clr Data
      Flower.NameList = Flower.NameList !Name
      call value 'Flower.'!Name'.Height', Ht
      call value 'Flower.'!Name'.Color', Clr
   end
   call ShowAll
   exit

   ShowAll: procedure expose Flower.
   do w = 1 to words(Flower.NameList)
      !Name = word(Flower.NameList, w)
      say !Name':'
      say '   Height:' value('Flower.'!Name'.Height')
      say '   Color: ' value('Flower.'!Name'.Color')
   end w
   return

And now you may be asking, Why use Value()? It is easier to just type
Code: [Select]
    Flower.!Name.Height = Ht
    say Flower.!Name.Height

It is easier to type and read, and I often do that myself. You just need to
be careful about the case of the variable name. In this:
Code: [Select]
    !Name = 'Crocus'
    Flower.!Name.Height = Ht
Rexx does not create the variable FLOWER.CROCUS.HEIGHT, it creates
FLOWER.Crocus.HEIGHT. So to display that variable with
Code: [Select]
    say Flower.!Name.Height
you must make sure that !Name is 'Crocus', not 'CROCUS' or 'crocus'.
What I do is always make !Name upper-case, as in
Code: [Select]
    !Name = translate('Crocus')

This is the only time I know of when Rexx variable names are case-sensitive. I
don't suppose it is really a bug, but maybe an oversight in the original design
of the Rexx language. Regina Rexx does the same thing.

Run the following script to demonstrate that Rexx can have several variable
names that differ only in case:
Code: [Select]
/**/
   if RxFuncQuery('SysLoadFuncs') then do
         call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
         call SysLoadFuncs
      end

   !Name = 'Crocus'
   call value 'Flower.'!Name'.Height', '"Crocus" using Value()'
   Flower.!Name.Height = '"Crocus" without using Value()'
   !Name = 'CrOcUs'
   Flower.!Name.Height = '"CrOcUs" without using Value()'
   drop !Name result
   say 'the list of known variables is:'
   call SysDumpVariables
   exit

This may be more advanced than what Alfredo had in mind, but I felt like sharing it.

2
I'm new in the forum and still catching up on old threads.

When I was learning Rexx I understood the advantage of a NoValue handler but didn't know how to write one. The following might be useful to provide for beginners.

Code: [Select]
   NoValue:
   /* ============================================================================== */
   /*  A simple NoValue handler that shows the name of the uninitialized variable    */
   /*  and the line where it occurs.                                                 */
   /*  it only uses are _ and __, which it assumes are not used elsewhere            */
   /* ------------------------------------------------------------------------------ */
   signal off NoValue
   _ = sigl
   parse source . . __
   __ = filespec('name', __)

   call lineout 'stderr', '['__'][NOVALUE Handler] at line '_' for variable "'condition('d')'"'
   call lineout 'stderr', copies(' ', length(__) +2)||'==> 'sourceline(_)
   call lineout 'stderr', copies(' ', length(__) +2)||'NOVALUE can also be triggered by a missing CALL'
   exit 9
   /* === End of NoValue =========================================================== */
 

Maybe it could be included in a suggested template,  in addition to the 'Hello World' example.

3
Programming / Re: REXX IDE recommendations?
« on: August 09, 2025, 02:52:46 pm »
Not IDEs, but a couple of things I like are

1) rxshell.cmd is an interactive shell where you can type Rexx commands and execute them mmediately. Similar to the RexxTry.cmd that comes with OS/2, but better.  Archive name is rxshell.zip.  OS2site.com has it and I have just uploaded it to the HobbesArchive.com incoming directory.

2) RexxTool.cmd is a Rexx analyzer/error checker/formatter that I call periodically from my text editor. It indents and formats the code neatly and catches some common typing mistakes. Like "unbalanced parentheses at line N" or "missing END somewhere after line N". Also some suggestions about what I consider good programming practices. I like it, but that's because I wrote it. I'd be interested to know if other people find it useful.  You can find the current version at
http://hobbesarchive.com/?dir=%2F&stype=all&sort=type_name&search=RexxTool.cmd&submit=Search

4
Programming / Re: Powerbasic for OS/2
« on: July 30, 2025, 09:57:56 am »
PowerBasic for OS/2 existed, but it was never released. It was reportedly nearly finished except for some OS/2-specific features. The last I heard about it was a post in the PowerBasic Compuserve forum that it would be available "in the relatively near future". That was in October 1998.


Pages: [1]