Tuesday, June 16, 1998 Beginning ARexx

The ARexx programming language, for that is exactly what it is, is commonly used for scripting and macro creation. It is, however, an interpreted programming language, capable for use in small programs, in addition to inter-process communication scripts. You don't need to be a programmer to understand how to write simple macros or scripts in ARexx, but it does help to know a little about programming in ARexx when creating more powerful scripts.

ARexx is the Amiga implementation of the Rexx programming language, designed for IBM mainframes. It is as capable of its counterpart, but also has many features that Rexx does not have. The Amiga version was created by William S. Hawes, and is included with every Amiga since the release of AmigaOS 2.0.

ARexx is an interpreted language. That means that each program or script is created entirely in ASCII text using a text editor, then when it is used the ARexx interpreter, called RexxMast, deciphers each line one at a time to determine what the program is trying to do, then performs the action. This method of execution is slower than compiled languages, like C, in which the code is directly converted into machine understandable code. Interpreted languages also has some advantages. For example, they are easy to modify and test, and it is also easier to identify and correct errors. Be sure that RexxMast is running before attempting to use ARexx scripts. It is easiest to just drop the RexxMast program into your WBStartup drawer, but you can also run it from your Startup-Sequence User-Startup by using the line: SYS:Utilities/RexxMast >NIL:

There have been released a few compilers for ARexx programs which take the ARexx program and compile the commands directly to machine code instructions, like Rexecute and RexxPlus. While the compiled versions are faster and hide the ARexx program code from others, there are minor problems in each of the implementations so far. For more information on compiled ARexx programs please check out one of the available compilers. This tutorial will not be going into that.

ARexx program files are usually named with an extension of .rexx. This allows you to execute the program without having to type in any file extension since .rexx is assumed by RexxMast. To execute an ARexx program from a CLI window simply type rx <filename> and if the program is in the current path, or in the REXX: assign, RexxMast will be able to find it and will execute it. Scripts written for specific applications sometimes require a special file extension in order to work. It is not always required, but is very helpful to name scripts for specific applications with an application specific extension. One example is Microdot2 by VaporWare software. It requires the ARexx scripts to have the extension of .mdrx. YAM by Marcel Beck does not require a special filename extension, but using the extension .yam reminds you and others that the script is designed for use with YAM.

Every ARexx program must start with a comment line. Comments are delimited, or set apart from the rest of the program with a backslash and asterisk combination, just like C programs. The first line comment tells the ARexx interpreter, RexxMast, that the program is indeed an ARexx program and not just a text file. The comment can say anything in it at all, but it is usually best to have descriptive comments. Here is an example:

/* My First ARexx Script */

Comments in ARexx scripts can be compatible with the version command by prefixing the comment with $VER: When you run version on the script it will return the information in the first line

/* $VER: MyScript.rexx v1.0 (06/16/98) */

Information in comments are ignored by the interpreter and are there for the programmer or user's information. Except for the first one on the first line, they are not required, but generally make programming, changing and updating programs easier when you use them to remind you what a particular part of your program does.

ARexx has its own list of commands which you can use in programs, such as SAY, which outputs text to the CLI window you ran it from. Commands are not case sensitive in ARexx but for convention standardization it helps to make them all in upper case. Here is a simple example:

sayhello.rexx
/* $VER: sayhello.rexx v1.0 (06/16/98) */
SAY "hello, world!"

When you execute this program it will output "hello, world!" with a new line to the CLI window. Character strings are delimited with single or double quotes. If you start a string with a single quote you have to end it with a single quote, you cannot mix them up. If you want to display a single quote in a string, for example in a contraction, you can use the single quote inside a double quote delimited string, or use a single quote twice in a single quote delimited string, like this:

"I don't like this"
'I don''t like this'

Variables in ARexx are similar to those in BASIC. They do not need to be predefined as specific types and can hold any type. Variables are not case sensitive, so the variable var1 and VAR1 are exactly the same. All variables in ARexx have a unique feature of being set to the upper case string of their name until they are set to a value. Here is an example:

variables.rexx
/* $VER: variables.rexx v1.0 (06/16/98) */
SAY hello
hello = 1
SAY hello
hello = 'hello, world!'
SAY hello

The output of the code will be:

HELLO
1
hello, world!

ARexx is very simple and very powerful. After learning a few things you will be able to unleash a lot of hidden power within your Amiga and may wonder why you hadn't started learning ARexx before. The most important thing to remember, however, is to have fun. If what you are doing is not enjoyable it really isn't worth doing. There are many others out there who program ARexx scripts for fun and may not mind creating a script or two for you if you would prefer not to do it yourself.