💾 Archived View for mirrors.apple2.org.za › archive › apple.cabi.net › Languages.Programming › IRep … captured on 2023-05-25 at 00:24:50.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

The IRep Language

Variables
---------
IRep supports integer and string variables.  Variable names must begin
with a letter, but subsequent characters may be digits.  String variables'
names must end in a $.  Variables do not need to be declared before they
are used.
IRep is case insensitive; xyz, Xyz, and XYZ and refer to the same value.

Expressions
-----------
Numerical expressions may include the following operators:
   + (addition), - (subtraction), * (multiplication), / (division),
   ^ (exponent), = (equal to), <> (not equal to), > (greater than),
   >= (greater than or equal to), < (less than), <= (less than or equal to)
The logical "and" and "or" operators may also be used

String expressions may include the following operators:
   = (equal to), <> (not equal to), > (greater than),
   >= (greater than or equal to), < (less than), <= (less than or equal to)
Comparisons between strings are based on alphabetical order; "aab" would
be greater than "aaa".  Note that these comparisons are case sensitive -
lower-case letters are considered greater than capital letters.

Strings may contain embedded numerical and string expressions enclosed
in braces.  For example, the string "2^4={2^4}" is interpreted as "2^4=16".
These embedded expressions may contain variables and predefined costants.

The "substr" function can also be used in string expressions.  It can extract
a series of characters from a string.

Syntax: substr(string,start,num)
   start - indicates the first character of the substring
   num - the number of characters to be extracted

Example: z$=substr("embedded",3,5) would set z$ equal to "bedde". The
   substring would begin at the third letter of "embedded" and would continue
   until a five-character result was produced.

A "strlen" function is also available; it returns a number representing the
length of a string.

Example: num=strlen("embedded") would set num equal to 8

Commands
--------

Type - Types a string

Syntax: type <modifier1,modifier2,...> str
Modifier keys (Apple,Option,Control,Shift,and Caps Lock) may optionally be
held down during typing.  The appropriate key names must be separated by
commas and listed between greater than and less than signs.

Examples:
   type "Hello"
   type <control,shift,capslock> Escape
   type var$


Say - Outputs a string

Syntax: say str

Example:
   say "Hello"


Ask - Requests input from the user

Syntax: ask var,prompt

Example:
   ask name$,"What is your name?"


If - Conditionally performs an action

Syntax: if expr then
           command/block
        else command/block

A single command or block of commands can be performed if the expression
is true.  A block is a group of commands surrounded by square brackets
([ and ])

An optional "else" section may be included.  The command ("if"s are allowed)
or block following the "else" will be performed if the expression in the
preceding "if" is not true.

Examples:
    if num=5 then
       say "Correct"
    else say "Incorrect"

    if a=3 then
       say "a=3"
    else if a=4 then
       say "a=4"

    if str$="Foo" then
    [
       type "{3*4}"
       type zz$
    ]


For - Repeats an action a specified number of times

Syntax: for counter=expr1 to expr2
           command/block
Counter will begin with the value of expr1 and will increase each time the
command or block is executed.  The command will be repeated until the counter
is equal to expr2.

Example:
   for count=1 to 5
      say "{count}"

While - Repeats an action while a certain condition is met

Example:
   while count<5
   [
      type "{count}"
      count=count+1
   ]

; - Comment

Any text between a semicolon and the end of the line is considered a comment.

Example:
   type <apple> "S"     ; choose Save menu item


Predefined Constants
--------------------

Numerical:
   hour - current hour (ranges from 0 to 23; 0=12 AM,23=11 PM)
   minute - current minute
   month - current month
   day - current day
   year - current year

String:
   monthname - name of the current month
   dayname - name of the current day

These constants correspond to the codes for some frequently used
keyboard keys:
   tab
   esc
   delete
   return
   uparrow
   downarrow
   rightarrow
   leftarrow


Sample Scripts
--------------
Here are a few simple examples of IRep scripts.

The following script types a line of text ten times.

ask text$,"Enter your text"
for count=1 to 10
[
   type text$
   type Return
]

A while loop could have been used instead of the "for"

ask text$,"Enter your text"
count=1
while count<=10
[
   type text$
   type Return
   count=count+1
]

The script can be modified to ask the user for the number of repeats

ask text$,"Enter your text"
ask repeats,"Enter the number of repeats"
for count=1 to repeats
[
   type text$
   type Return
]

Another script can open and print a file from many applications.

ask filename$,"Enter the filename"
type <apple> "o"
type filename$   ; Type the filename into the Open File box
type Return
type <apple> "p"
type Return

This script will type the time in HH:MM AM/PM format

if hour=0 then
   type "12:{minute} AM"
if hour>0 and hour<12 then
   type "{hour}:{minute} AM"
if hour=12 then
   type "12:{minute} PM"
if hour>12 then
   type "{hour-12}:{minute} PM"

The "year" constant contains the complete year number (e.g. 1993)
This command will type the last two digits of the year.

type "{substr("{year}",3,2)}"

This command will type the first half of a string

ask str$,"Enter the string"
type "{substr(str$,1,strlen(str$)/2)}"