PROGRAM PASS;
VAR I: INTEGER;
ST1; STRING;
TABLE: ARRAY [0..50] OF STRING (* For this program to run, *)
(* TABLE must be initialized*)
(* prior to calling DOIT. *)
FUNCTION DOIT (VAR ST2; STRING; INDEX: INTEGER):BOOLEAN;
(* VAR designates ST2 as a VARiable parameter.*)
BEGIN
DOIT := TRUE;
IF LENGTH(TABLE [INDEX]) = 0 THEN (*DOIT returns false if *)
DOIT := FALSE (*the given entry(INDEX)*)
ELSE ST2 := TABLE [INDEX] (*in the table is null. *)
END; (*ELSE, IT RETURNS TRUE.*)
BEGIN
FOR I := 0 TO 50 DO
BEGIN (* ST1 should be null unless *)
ST1:= ''; (* DOIT alters it. *)
IF DOIT(ST1,I) THEN (* If the array entry is not *)
WRITELN(ST1) (* null, print the string. *)
END; (* FOR *)
END.
Notes:
1. An individual element of a packed variable cannot be supplied as the actual parameter. See page 90 of the Apple III Pascal Programmer's Manual, Volume 1.
2. The addresses of strings are ALWAYS passed to the procedure or function, whether the string is a VARiable parameter or a value parameter. Declaring the string parameter to be a VARiable parameter avoids coping the entire valueof the string to the function and attendant lowering of memory and performance. Bear in mind that, it is generally good programming technique to use value parameters wherever possible for maximum "decoupling" of function and calling program.