Documentation
Getting Started
New Features
Component Guide
Programming
    Language Guide
    Language Ref.
       General Design
       Lexical Structure
       Expressions
       Objects
       Methods
       Classes
       heitml Tags
       heitml Functions
       Database Access
       Global Variables
       Form Fields
       Server Variables
       Sessions
       heitml Syntax
    Component Ref.
    Class Library
    User Components
    Tryout Form
    Tutorial
    heitml 1
User Guide
Registration
Frame
    

Methods

Methods can be defined using the def or defenv tag.
Syntax:
heitml::= <def MethodName FormalParameterList > DefinitionModifiers
    Body
</def>
| <defenv MethodName FormalParameterList > DefinitionModifiers
    Body
</defenv>
| ...
Body::= heitml *
Every method belongs to a class. Methods defined inside a Class belong to that class. Top level methods (that are not located inside a class definition) belong to a predefined class named Page.

Calling Top Level Methods

Top level methods can be called using the tag-syntax or using the function call syntax. In both cases a function call executes the body of the def or defenv tag.

Tag Syntax for Method Call

The tag syntax to call a method is
Syntax:
heitml::= < MethodName ActualParameterList > [ Content </ MethodName > ]
Content::= heitml *

This resembles the usual HTML or XML syntax. One can choose between HTML compatible and heitml extended parameter lists.

Example:

heitml input:
<def Hello>
Hello World
</def>
<Hello>
resulting output:

Hello World

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.

Example:

heitml input:
<defenv Big>
<font size="+3"><defbody></font></defenv>
<big>Hallo</big>
resulting output:

Hallo

Visibility

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.

Example:

heitml input:
<def Hello></def>
<Hello>
<def Hello>Hello World</def>
<Hello>
resulting output:

Hello World Hello World

Function Call

Syntax:
Expr::= FunctionName ( ActualParameterList )
The function call syntax can be used to call top level methods and built-in functions. The method must be defined using the
def-tag and it must contain a return tag. A function call is an expression. During evaluation the function is called. The result of the expression is the value returned with the return tag.

Example:

heitml input:
<def plus a b; return a+b; /def>
<? plus(5,7)>
<? plus("Hello ", "World")>
resulting output:

12 Hello World

Local Variables

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.

In contrast the variables ff, se, page, and gl are Global Variables and can be accessed everywhere. These are objects and can therefore contain as many global fields as desired.

Example:

heitml input:
<def myfun>
<let a=1; gl.b=2;>
</def>

<let a=5; gl.b=6>
<myfun>
<?a> <?gl.b>
resulting output:

5 2

Parameter Passing

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
Syntax:
FormalParameterlist::= ( ParameterName [= Expr ]  | * ParameterName  | ** ParameterName
      | @ VariableName  | @ this
  ) * [ ... ] .

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
Syntax:
ActualParameterlist::= ( [ ParameterName = ] Expr ) * .
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.

Example:

heitml input:
<def mytag a b=5 c=9>
   <? a>, <? b>, <? c><br>
</def>

<mytag 1 2 3>
<mytag 7>
<mytag c=11 7>
<mytag a=5 c=11>
<mytag (1,2,3); mytag(a=5 c=11)> 
resulting output:

1, 2, 3
7, 5, 9
7, 5, 11
5, 5, 11
1, 2, 3
5, 5, 11

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)

Example:

heitml input:
<def mytag *a b=5 c=9>
   <let a = b + c> 
</def>
<mytag a 2 3> <?a> <br>
<mytag a> <?a>
resulting output:

5
14

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.

Example:

heitml input:
<def myimg @p src ... >
<let p.src="/heitml2.0/pictures/" + p.src>
&lt;img <? p "Pn"> &gt
</def>
<myimg src="web.jpg" width=20 height=50>
resulting output:

<img src="/heitml2.0/pictures/web.jpg" WIDTH="20" HEIGHT="50" >

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.

Example:

heitml input:
<def cnt **oid; inherit Object;
    this.i=default(this.i,0)+1;
    ? this.i;
 /def>
<cnt a>, <cnt "b">, <cnt a>, <cnt a>, <cnt "b"> <br >
<? a "n"><br >
<? page.b "n">
resulting output:

1, 1, 2, 3, 2
a=cnt(i=3)

b=cnt(i=2)


This page was dynamically generated by heitml
© 1996-2009 H.E.I. All Rights Reserved