Author Topic: REXX tutorials -- start developing applets under ArcaOS out-of-the-box  (Read 7244 times)

Alfredo Fernández Díaz

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +4/-0
    • View Profile
I think it is a shame that the default ArcaOS 5.1.1- installation has a 'Development' folder... populated with the single lonely 'Rexx console' object pointing to PMRexx. While somebody should try and convince the guys at ArcaNoae that 'less is more' does not apply in this case (don't we want more programming languages?), can't we tell them here and now how to improve what's currently available? Even better, can we show them? ; )

Let's start with extremely simple things: make more stuff visible by adding it to the Development folder!
1. RexxTry (a procedure that lets you interactively try REXX statements) is localized in ArcaOS 5.1.1 -- so, don't you want users to know it's there? Add "Try Rexx!" (both VIO and PM, using the 'REXX Console'!) objects.
2. Doesn't the system include a gazillion system and additional REXX libraries already? Why not have a shadow of the "REXX scripting language" folder right next to the other REXX objects in Development, so only the illiterate can miss the information?

OK, that was the obvious. Now, from another thread... tutorials?!:

I see that the knowledge of REXX is somewhat limited even with OS/2 users.
[...]
So what can one do with REXX you wonder?
Alex Taylor has for example written some excellent software that you may have used, both command line scripts and GUI applications like Naps and ANPM to mention a few.
Glassman wrote AutoWGet that is very helpful to fetch things from the internet
and much more...

I use ooRexx to automatically create documents with maps to send to owners of land at work, drive office applications, vector drawing applications such as OpenOffice Draw, Calc etc. split/merge/extract text PDF documents with GhostScript and retrieve routes from google between places etc.

I myself have written a few dozens of simple rexx programs. While they may not be spectacularly useful for everyone I wrote them in REXX with the idea that anyone could see right away how stuff is done, and maybe this could pique the interest of more people (or new users?) than what is currently included with the system -- who doesn't like a good tutorial? So, I could try and turn what I have into one <g> if you guys think it could be of interest and are willing to provide useful feedback.

[...] I would welcome any additional tutorial material to help me improve [...]

So, I propose to post here applets, code snippets, and anything REXX really, aimed at
1. Usefulness for less experienced users or developers who may be scratching their heads wondering 'OK, the reference is fine, but how do I...?', or 'how does one put together X and Y?', etc.
2. Creating some fine multi-level tutorial worth being included in next releases of ArcaOS.

I will try and put together a few usable examples. Meanwhile, do not hesitate to share your knowledge here, or simply comment on how what's being posted could be improved for you!

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1419
  • Karma: +27/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #1 on: February 22, 2025, 03:26:48 pm »
Hello Alfredo!

The topic you raise here is equally applicable to all the other programming languages on our platform.

'Knowledge is Power', right?

So I would suggest that where things start for us is in establishing a good Developer Library/References.

I've attached what such a library looks like on my machine, specifically focusing on REXX. This is a mix of freely available information, as well as PDF downloads of previously commercial books, etc.

Now you may argue that the PDFs in particular are illegal, etc., etc....OK, fine, so why not provide an executable d/l script that simply uses wget to pull this list down from any of the well recognized archive sites??? That way each end-user makes this decision for themselves!

Bottom line being: tutorial, try-by-example, all these things are great, but when you are new to something you ultimately need a solid 'something to go to in order to understand what the example code/API does', and that's the missing piece for us I think.

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +7/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #2 on: February 22, 2025, 05:50:00 pm »
Yes!

There are so much one can do with REXX.
Newer versions (ooRexx) can often do more with less (code).

Do show us some and let's begin there.

Steven Levine

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +12/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #3 on: February 22, 2025, 06:37:03 pm »
If one is interested in REXX, I recommend taking a look at Glassman's ooREXX port.

  https://5nets.ru/downloads/?/OORexx

It's not quite ready to replace IBM's Classic REXX or Object REXX.  The build is missing a couple of exports that break SSCC and possibly a few other REXX apps.

However, I use it regularly, especially for code that would cause IBM's REXX's to run out of memory.

IIRC Dave Yeo did a local build, but we have not discussed its status.


Dave Yeo

  • Hero Member
  • *****
  • Posts: 5319
  • Karma: +125/-1
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #4 on: February 22, 2025, 07:25:00 pm »
IIRC Dave Yeo did a local build, but we have not discussed its status.

I don't think it was I who did a local build.

Lewis Rosenthal

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +7/-0
    • View Profile
    • Tales from the Trenches of IT
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #5 on: February 22, 2025, 09:50:05 pm »
I could see Arca Noae providing a WarpIN package via the repository which would install a collection of REXX books and code snippets, which would be shadowed/created in the Development folder. Likewise, I could see similar packages for OREXX, Regina, PHP, Python, Perl, etc.

We could also consider adding a number of useful links to the Websites folder (currently "Web Sites," but slated to be renamed to something more contemporary - at least in English). This is an underused resource on the desktop the use of which we could also promote better.

From Arca Noae's perspective, adding more content to the ISO itself is the least desirable option for things which could be installed after-the-fact and kept updated between ISO releases.

Lewis
-------------------------------------------------------------
Lewis G Rosenthal, CNA, CLP, CLE, CWTS
Managing Member
Arca Noae, LLC                               www.arcanoae.com

Alfredo Fernández Díaz

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +4/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #6 on: February 22, 2025, 10:58:55 pm »
Hi Dariusz, Steven, Jan-Erik, Dave, Lewis -- that's the idea!

Well, so for the moment being and me cRexx it is, as it is available for everyone by default, and I expect by the time any advantages of (o)oRexx become a necessity for people, they should be able to simply switch from tutorials to reference manuals -- mind you, of course any comments on how 'the same can be done with less --or otherwise better-- (o)orexx code like this' are most welcome!

As Dariusz pointed out, it is always an excellent idea to have a bibliography covering any subject at hand in depth, either in the form of the books themselves if available, or at least a list, so thank you for that. However, I think the best tutorials, while referring to appropriate materials where everything is covered in full, do at the same time keep their own stuff at a minimum to ensure everything can be grasped in one go.

Every year I find myself having to match syllabi/syllabuses which are impossibly broad and deep to the corresponding exams, so you see where I come from. Rather than going for the mechanical 'recipes for exercises' approach, every year I have a(nother) go at condensing (butchering, really) each subject in such a way that students will stand some chance to do well at their exams while it still makes sense as a whole for those who really want to understand -- with any luck, I'll have enabled some to pick up a book and make sense of the real stuff when laid out in proper depth. I like to think I slowly get better at it, so let's see what we can do here... ; )

Alfredo Fernández Díaz

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +4/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #7 on: February 22, 2025, 11:01:58 pm »
I imagine we can start with something rather basic and see if can give this some shape so it is useful for those who might find the relevant parts of the crexx reference overwhelming or otherwise unappealing.

The following procedure

Code: [Select]
/**/
parse arg where
call lineout where,'     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5'
do i=1 to 15
  call charout where,' '||right(i*16,3,' ')
  do j=0 to 15
    call charout where,' '||d2c(i*16+j)
  end
  call lineout where,' '||right(16*i+15,3,' ')
 end
call lineout where,'     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5'
call lineout where
exit

will print out the following ASCII table:

     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  16                  31
  32   ! " # $ % & ' ( ) * + , - . /  47
  48 0 1 2 3 4 5 6 7 8 9 : ; < = > ?  63
  64 @ A B C D E F G H I J K L M N O  79
  80 P Q R S T U V W X Y Z [ \ ] ^ _  95
  96 ` a b c d e f g h i j k l m n o 111
 112 p q r s t u v w x y z { | } ~  127
 128 Ç ü é â ä à å ç ê ë è ï î ì Ä Å 143
 144 É æ Æ ô ö ò û ù ÿ Ö Ü ø £ Ø × ƒ 159
 160 á í ó ú ñ Ñ ª º ¿ ® ¬ ½ ¼ ¡ « » 175
 176 ░ ▒ ▓ │ ┤ Á Â À © ╣ ║ ╗ ╝ ¢ ¥ ┐ 191
 192 └ ┴ ┬ ├ ─ ┼ ã Ã ╚ ╔ ╩ ╦ ╠ ═ ╬ ¤ 207
 208 ð Ð Ê Ë È € Í Î Ï ┘ ┌ █ ▄ ¦ Ì ▀ 223
 224 Ó ß Ô Ò õ Õ µ þ Þ Ú Û Ù ý Ý ¯ ´ 239
 240 ­ ± ‗ ¾ ¶ § ÷ ¸ ° ¨ · ¹ ³ ² ■   255
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5


Notes (before you tackle the full rexx reference):
-The procedure can print to a file using the filename as a parameter. If omitted (empty), the table will be printed to screen. Individual instructions "charout" and "lineout" do the same.
-Characters are produced sequentially according to their codepoint number because there is a simple way to convert numbers to characters. Check "d2c".
-Initial and final reference values are padded on the left to take up 3 spaces and stay aligned on the right. Check "right".
-The actual characters shown depend on system codepage. Try this on a separate session after the command "CHCP <secondary codepage>", and compare.
-Should it be mentioned that the two nested loops for rows and individual cells within each row need two different indices, but that these can be used separately and together (e.g. to calculate the code for each current char)?

As you see, the idea is that we take some simple task (for the level considered), complete it with a minimal set of basic instructions, and comment on some aspects that being interesting can be easily overlooked when reading a full reference. Rinse and repeat with more advanced stuff.

Does this look any good to you? What would you improve? Post your own, better examples ; )

Edit: tt -> code
« Last Edit: February 27, 2025, 01:11:23 am by Alfredo Fernández Díaz »

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +7/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #8 on: February 25, 2025, 04:10:30 pm »
/**/
parse arg where
call lineout where,'     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5'
do i=1 to 15
  call charout where,' '||right(i*16,3,' ')
  do j=0 to 15
    call charout where,' '||d2c(i*16+j)
  end
  call lineout where,' '||right(16*i+15,3,' ')
 end
call lineout where,'     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5'
call lineout where
exit


It is often just a matter of personal taste and preference, so the code to output that can be written in many ways and they'll serve well, thus cause frustration and confusion for beginners that want one and only one solution to cling to.

But here goes, assuming that the code has been saved to "charcode.cmd":
parse arg where and every occurance of where can be omitted in this case, as one can type "charcode > c850.txt" to save it to file c850.txt

How about a loop for:
call lineout ,'     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5'
such as:
do i = 0 to 15 /* loop 16 times, start at 0 and end at 15 */
  call charout , right( i, 2 + 4 * ( i = 0 ) , ' ' ) /* output a number, with 1 space in front and 4 more if loop number is zero*/
End
SAY /* This "say" without anything else just add a new line character */


Gordon Snider

  • Newbie
  • *
  • Posts: 8
  • Karma: +3/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #9 on: February 25, 2025, 07:48:08 pm »
Sorry if I'm not doing this right.  I am a very infrequent contributor  and am still learning the ropes.

The code below is for anyone who wants to visit all directories, one by one, below the current directory
as root,  out to the "leafs".  It makes use of recursion inside a loop.  It actually visits each directory
twice, once on the "head" recursion and again on the way back in,  "tail" recursion.

It assumes RexxUtil.DLL HAS ALREADY BEEN LOADED.  (I load it at boot time.)
   
You can find lots of nooks and crannies to put features in. 


/* KERNEL          CMD by Gord Snider  v1.0                                  */
current = Strip( Directory(), 'T', '\')         /* save fully qualified current directory for return */
SAY current                                     /* say current directory */
CALL next current                               /* call to check for sub-directories */
EXIT 0

next: PROCEDURE                                 /* hide old set of variables, enable new set */
PARSE ARG nextdir,spacer                        /* spacer is each line's indenting characters */
CALL SysFileTree Strip( nextdir, 'T', '\') || '\' || '*', 'dir.', 'DO'  /* are subfolders here? */
DO dir = 1 TO dir.0                             /* if any, make a list of them and process it */
   IF dir < dir.0 THEN leader = D2C(195)
                  ELSE leader = D2C(192)
  SAY spacer || ' ' || leader || SUBSTR( dir.dir, LASTPOS('\', dir.dir) + 1)
  IF leader = D2C(195) THEN leader = D2C(179)
                       ELSE leader = ' '
  CALL next dir.dir, spacer || ' ' || leader    /* pivot point of the recursion */
END dir                                         /* back to top of dir loop */
RETURN                                          /* a leaf has been reached */

Alfredo Fernández Díaz

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +4/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #10 on: February 26, 2025, 08:05:21 pm »
Jan-Erik, Gordon, thank you both for your input.

I think code snippets for tutorials should be as simple and straightforward as possible so as to show one way to address the task at hand and get it done right away.

As you point out, however, anything worth doing can probably be done in a number of ways, and different developers can find places in any listing where adding / replacing some code can improve the whole thing, so I'll ammend the above by adding "initially". Just like classes on the same subject are always the same yet always a little bit different if only because of the audience, different people will take away slightly different things from one tutorial so it is probably a good idea to have different code listings to illustrate possible alternatives or whatever. That's the spirit!

Putting everything together, maybe this could be better done in the form of a simple initial listing, plus additions to expand on obvious or non-obvious places. Let's try that with another REXX snippet...

Alfredo Fernández Díaz

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +4/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #11 on: February 26, 2025, 08:10:15 pm »
Code snippet #2: timed command

Rationale: one good thing about REXX is that it lets you use system commands in your code, which makes integrating both very easy. It is sometimes interesting to know how long some commands take to complete, so why not use some simple REXX to execute them and find out?

This REXX code will take its execution parameters as a command to be executed as is by the system shell, will report the time elapsed, and pass along its exit (return) code:

Code: [Select]
/*
  Timed Command: executes its invoking parameters as an
  external system command, and tells how long it took
*/
parse arg command

/* Depending on command output, this may go off-screen > repeat at the end */
start = time()
say 'Starting "'||command||'" at '||start
call time 'E'  /* start timer */

/* Single literals execute as commands */
'@Echo Off'   
command       
cmdrc = rc     /* save return code */

say 'Command: "'||command||'", '||,
    'started at '||start||', ended at '||time()||'. '||,
    'Elapsed: '||format(time('E'),,2)||'s.'
if cmdrc <> 0 then /* simple warning */
  say 'Non-zero exit code (error?): '||cmdrc

exit cmdrc /* RC is passed along regardless of value */

Some refinements are possible. For example, time can be formatted if too many seconds are uncomfortable to read:

Code: [Select]
[...]
say 'Command: "'||command||'", '||,
    'started at '||start||', ended at '||time()||'. '||,
    'Elapsed: '||t2hms(time('E'))||'.'
if cmdrc <> 0 then /* simple warning */
  say 'Non-zero exit code (error?): '||cmdrc

exit cmdrc /* RC is passed along regardless of value */

t2hms: procedure
  parse arg t
  h = t % 3600
  t = (t // 3600)
  m = t % 60
  s = (t // 60)
  t = format(s,,2)||'s'
  if (m > 0) then do
    if (s < 10) then
      t = '0'||t
    t = m||'m:'||t
   end
  if (h > 0) then do
    if (m < 10) then
      t = '0'||t
    t = h||'h:'||t
   end
return t

What if commands include redirection?

Some commands are most useful when executed redirecting their output to a file, e.g. "dir > filelist.txt", but executing "TimedCmd dir > filelist.txt" will include TimedCmd output in filelist.txt in the example, which may not be desirable.

To adress such situations, the whole command must be in quotes so it is passed as a single parameter for execution leaving the redirection to be processed later, i.e. TimedCmd "dir > filelist.txt" in the example above. However, the quotes must be removed from both ends so the system shell will break the command again to carry on the redirection, instead of looking for a file called "dir > filelist.txt" to execute:

Code: [Select]
[...]
parse arg command
command = strip(command,,'"')
[...]

Edit: tt -> code
« Last Edit: February 27, 2025, 07:51:05 pm by Alfredo Fernández Díaz »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5319
  • Karma: +125/-1
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #12 on: February 26, 2025, 11:48:19 pm »
These would be more readable by using the code markup, square bracket code square bracket, same to close except /code.
Code: [Select]
/*
  Timed Command: executes its invoking parameters as an
  external system command, and tells how long it took
*/
parse arg command

/* Depending on command output, this may go off-screen > repeat at the end */
start = time()
say 'Starting "'||command||'" at '||start
call time 'E'  /* start timer */

/* Single literals execute as commands */
'@Echo Off'   
command       
cmdrc = rc     /* save return code */

say 'Command: "'||command||'", '||,
    'started at '||start||', ended at '||time()||'. '||,
    'Elapsed: '||format(time('E'),,2)||'s.'
if cmdrc <> 0 then /* simple warning */
  say 'Non-zero exit code (error?): '||cmdrc

exit cmdrc /* RC is passed along regardless of value */

Thanks for the code.

Alfredo Fernández Díaz

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +4/-0
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #13 on: February 27, 2025, 01:18:46 am »
Wait, there's a proper use for the code tag in forums?! LOL
Thanks for the tip, Dave! : ))

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5319
  • Karma: +125/-1
    • View Profile
Re: REXX tutorials -- start developing applets under ArcaOS out-of-the-box
« Reply #14 on: February 27, 2025, 04:20:28 am »
Code snippet #2: timed command

Rationale: one good thing about REXX is that it lets you use system commands in your code, which makes integrating both very easy. It is sometimes interesting to know how long some commands take to complete, so why not use some simple REXX to execute them and find out?

This REXX code will take its execution parameters as a command to be executed as is by the system shell, will report the time elapsed, and pass along its exit (return) code:

Code: [Select]
/*
  Timed Command: executes its invoking parameters as an
  external system command, and tells how long it took
*/
parse arg command

/* Depending on command output, this may go off-screen > repeat at the end */
start = time()
say 'Starting "'||command||'" at '||start
call time 'E'  /* start timer */

/* Single literals execute as commands */
'@Echo Off'   
command       
cmdrc = rc     /* save return code */

say 'Command: "'||command||'", '||,
    'started at '||start||', ended at '||time()||'. '||,
    'Elapsed: '||format(time('E'),,2)||'s.'
if cmdrc <> 0 then /* simple warning */
  say 'Non-zero exit code (error?): '||cmdrc

exit cmdrc /* RC is passed along regardless of value */

Thanks for the better formatting. I tried running the above snippet after saving it as time.cmd and got,
Code: [Select]
K:\work\dooble\obj>time.cmd make clean
SYS1044: The system cannot accept the time entered.

Enter the new time:

Same with quoting the make clean.