procedure: Start a procedure script
Package: language
Syntax
procedure proc_name [( [req_par, ...] )]
<query mode parameter declarations>
<hidden parameter declarations>
begin
<local variable declarations>
<executable statements>
end
Elements
- proc_name
- The name of the procedure. In the case of a procedure script, the script file should have the same name.
- req_par
- A required (query mode) parameter for the procedure. Hidden parameters must be declared in the declarations section but do not appear in the argument list.
Description
The procedure statement is used to declare a new CL procedure. In the current CL, procedures are permitted only in ".cl" script files, and there may be only one procedure per file. The procedure statement must be the first non-comment statement in the script file. Any parameters which appear in the procedure argument list must be declared in the parameter declarations section as well and will default to mode "auto". Parameters not in the required parameter list will default to mode "hidden". The order of positional parameters is the order in which the parameters appear in the argument list.
Examples
1. Declare a no-op procedure.
procedure noop
begin
end
2. A more complex procedure (hlib$devstatus.cl).
# DEVSTATUS -- Print status info for the named device.
procedure devstatus (device)
string device { prompt = "device for which status is desired" }
bool verbose = no
string logname, hostname
struct *devlist
string dev
begin
dev = device
_devstatus (dev)
if (verbose) {
# Print UNIX device status, too.
devlist = "dev$devices"
while (fscan (devlist, logname, hostname) != EOF) {
if (logname == dev) {
print ("ls -l /dev/", hostname) | cl
break
}
}
devlist = ""
}
end
Bugs
CL procedures can only be placed in script files, they cannot currently be typed in interactively. Procedures cannot be precompiled. A procedure cannot return a function value. Arguments are passed only by value, not by reference. Procedure interpretation (and expression evaluation) is currently rather slow.
See also
declarations, task