Function Parameters

Script functions can be declared with parameters, which are passed to the function when it is called. Parameters are declared by naming them in the <A NAME> declaration tag, after the NAME attribute and any scope attribute (PUBLIC/PRIVATE etc.) . Each parameter is a local variable (here) inside the function:

<A NAME=banner title="Untitled" bg>
  <HEAD>
    <TITLE>$title</TITLE>
  </HEAD>
  <BODY BGCOLOR=$bg>
  <CENTER>
    <H2>$title</H2>
  </CENTER>
</A>

This function has two parameters, $title and $bg. When the function is called, its arguments are named in the tag (like HTML attributes):

<banner title="Search Results" bg=white>

Since the arguments are named, they need not be given in order (like HTML). Nor are all parameters required when calling: the $title parameter was declared with a default value of "Untitled", so it will have that value if unspecified in a call:

<banner bg=white>

Parameters without default values (e.g. $bg) are required in calls, however. This provides the ability to force their setting in situations where a default value might not be useful. For example, a search-and-replace type function could require its search and buffer parameters: it may not be sensible to search a default buffer. The exception to this is start functions: since they have no explicit "caller" to name arguments, no-default parameters in the start function are initialized like a global variable, i.e. from the appropriate environment, query, POST etc. variable of the same name.

The default value for a parameter can also be a variable:

<A NAME=banner title=$DefaultTitle bg>
  ...
</A>

In this case, if $title is not specified in a call, it will have the value of the global (never local) variable $DefaultTitle.


Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.