ARexx For Beginners (Part 1)

Jason Northcott

<jasonn@satech.net.au>

Hello and welcome to the first part of an ongoing series that I will be writing, based upon the ARexx language. If you are a complete beginner then I suggest you read the introduction and installation sections first before continuing on with the rest of the tutorial.

1 - INTRODUCTION

ARexx is a high level programming language for the Amiga that is designed specifically for controlling other programs externally. It was first introduced to the Amiga range when Amiga DOS 2 came out and has been with us ever since, so if you dont have Amiga DOS 2 or higher then I suggest buying a copy before you continue. If you have a copy of ARexx handy then proceed to the next section.

2 - INSTALLATION

ARexx comes mainly in three parts, the program RexxMast, the cli executable rx and all the other bits and pieces required for ARexx. If you intend to use ARexx on a permanent basis (ie, if you are going to follow this tutorial) then I suggest you put the RexxMast program in your WBStartup drawer. Now, you must place the program rx and its counterparts into a drawer, preferably on your system disk, and assign REXX: to that directory. For example, if I put all the exec's in a drawer called sys:rexxc/ then I would add the following line to my user-startup:

assign REXX: sys:rexxc

and thats all there is to it! ARexx will now be up and running on your system everytime you boot.

3 - YOUR FIRST AREXX PROGRAM

By now ARexx should be up and running on your system so it's time to learn how to program. All of the programs that are documented in this series can be entered straight into a text editor and then run with the following command:

rx <program>

So if I had just written a program with a text editor and I saved it with the name hd1:example1.rexx then I would open a cli/shell and simply type
rx hd1:example1.rexx

at the prompt.

We shall begin with the most basic program that I think every language tutorial ever begins with and that is the famous "hello world" program.

	/* My first program */
	say "Hello World"

Looks pretty simple doesn't it? Now to cover it in full. The first line is a comment. All ARexx programs must start with a comment. A comment is started with "/*" and ended with "*/", and everything in between them is ignored by the interpreter. The second line consists of a command and a string, the command being say and the string being "Hello World". What the say command does is to simply type the words inside the quotations onto the console (ie the cli/shell). Lets take a look at another example, this one prompts the user for their age and then tells them approximately how many days old they are.
	/* Age in days */
	say "Please enter your age"
	pull age /* <--- New command! */
	say "You are approx" age*365 "days old!"

The only thing different about this program that you may have noticed is the command pull. This command waits for the user to enter something, followed by a carriage return and then puts it into a variable. In this example, age is the variable (a variable can be any word as long as it isn't an ARexx command). So if I entered "23" as my age then the variable age would contain, you guessed it: 23. Notice that there is a second comment in this program, that was put there to demonstrate that not only can you have a comment at the start of a line, but anywere you like. The next line simply takes your age in years and multiplys it by 365 (Days in a year) and prints it out. I will explain how this works.

First, the say command prints the string inside the first set of quotes ("You are approx"). Next, is a mathematical calculation: age*365. '*' is the symbol for multiplication, and this expression takes the variable age (which is equal to 23, or whatever you entered - 23 for examples sake) and multiplies it by 365. The say command then would print out the answer - which would be in this example, 23*365=8395. Lastly, the string inside the second set of quotes would be printed. So in the end, the final say command would print

You are approx 8395 days old!


Some questions to think about, with answers in the next tutorial:

  1. What would happen in the second example program if I put quotes around the whole line? What would the say command print?
  2. If I told you my friend was 11680 days old, could you write a program to tell me how many years old she is? If so, what is it?


Well I think that may be a good place to finish the first of my beginner tutorials in ARexx. If you enjoyed this tutorial or you want to get into some more exciting programs then stick around for my next tutorial, out soon. I'll leave you with some operators that can be used with a variable, like we did with the age variable (age*365)..


Table of Contents