proc procname(arguments ...)arguments is a comma separated list of variable names. The proc command is followed by the body of the subroutine - Jive commands. The definition is terminated by the end command. The proc definition can be within braces, or it can be external:
{proc li(str)}
<li>{str}
{end}
A subroutine defined with proc is executed with the call
command:
call li('Item 1')
Arguments for call are passed by reference. When the
argument is a variable name, its reference is passed to the proc,
which can alter its value. For example:
proc incrm(arg)
set arg = arg + 1
end
var int index = 0
call incrm(index)
After the call, the variable, index, will contain a 1.
Arguments for a proc are not typed. For example, incrm, defined above, can be called with a string argument:
var string value = '0' call incrm(value)Literals and expressions can also be used as arguments in call. Arguments can be omitted, passing a null value. The associated proc argument name can still be assigned values, but results are discarded when the proc ends.
Unlike functions, the name in a call command must be followed by parentheses, even when the proc takes no arguments or none is passed. A proc definition does not have a return value, but it can alter its arguments.
Example (this proc definition prunes trailing blanks from a string):
proc trim(str)
var work[] = @ str, i = # work
while i and not work[i - 1]
set i = i - 1, work[i] = null
end
set str = @ work
end