Calling Top Level Methods
Tag Syntax for Method Call
The tag syntax to call a method is
This resembles the usual HTML or XML syntax or an element. A method defined with def may be called with a single BeginTag or a EmptyElementTag. A method defined with defenv may be called with a BeginTag and a EndTag or with an EmptyElementTag. Note that the EndTag must not be present in case of a def and it must be present in case of a defenv. To retain HTML compatibility there is the defautoclose declaration that automatically inserts missing EndTags in certain cases.
One can choose between HTML compatible and heitml extended parameter lists.
A method defined with the def-tag must be called without the content and the end tag. A method defined with the defenv-tag must be called with content and end tag. The identifier of the end tag must match the identifier of the start tag.
A method can be called only after it has been defined. In this case, the word "after" refers to the sequence of text in the input file.
Methods can be redefined; however, the type of method (def or defenv) must stay the same. Always the textually last definition is taken. This way it is possible to use an initial empty definition for a method as a kind of forward declaration.
Methods can also be called recursively. If two methods call each other recursively, it is necessary to define one first as empty, and afterwards redefine it.
Every method has its own set of Local Variables. They are visible and can be access only within this single method. Variables of the calling method or called methods can not be accessed. If methods call each other recursively, multiple incarnations of the local variables exist.
Methods can have parameters. Using the formal parameter list at the definition parameters can be specified. These parameters can then be passed by a method call. A def or defenv tag can have a formal parameter list of the form
Parameters marked with an asterisk * are Output Parameters. Parameters marked with ** are Id Parameters. All other parameters are Input Parameters. The optional Expression associated with a parameter is called Default Value. The variable given after a @ is named target variable.
Now please consider a method call with an ActualParameterList
All parameters with the optional "Identifier =" in front are called Keyword Parameters. Parameters without the "Identifier =" are called Positional Parameters.
During the call every Actual Parameter is associated with a Formal Parameter: The actual parameter in the n-th position is associated with the n-th formal parameter. A Keyword Parameter is associated with the Formal Parameter having the same name.
It is a bug if there are two actual keyword parameters with the same name or if a Keyword Parameter and a positional parameter are associated with the same formal parameter. If a formal parameter has no actual parameters associated with it, then the Default Value is used instead. If no default value is given the parameter must be specified by a call. The called method or function gets a local variable for each formal input parameter containing the value of the associated actual parameter.
For Output Parameters the Actual Parameter has to denote a variable or an object field. When the called method returns, the Formal Parameter is assigned to the Actual one. (i.e. a Local Variable of the method with the name of the Formal Parameter)
Using the @ syntax, parameter values can be stored in an object, rather than passing them as local variables. All parameter values that occur after the @ are put into an object. It can be referenced by the variable name following the @. Access to an actual parameter is done by referencing the object field with the name of the corresponding formal parameter.
If the last parameter is followed by ..., parameters may be passed for which no formal parameter exists (anonymous parameters). This is very useful in tag redefinitions, that only handle a subset of the parameters of the original definition. Using @, the anonymous parameters may be processed by looking for object fields with a name that does not occur in the formal parameter list.
Only a class constructor may have an id parameter (marked with **). The actual parameter must either denote a variable or evaluate into a string s. In the latter case, the variable page[s] is taken. If the variable is not defined or contains null, the object created by the constructor is assigned to the variable upon creation. If the variable exists and has a value other than null, it must contain an object. Instead of creating a new object the constructor uses this object to work on. The object becomes accessible by this inside the constructor. Unlike other parameters the parameter value is accessible by this and not by the parameter name specified. As an exemption to this rule a string value passed to an id parameter is accessible by the parameter name.
© 1996-2017 H.E.I. All Rights Reserved.