Method Statement

Defines a method procedure for a class or library.

Syntax

Standard form
[ modifier ] Method name [ < typeList > ] [ parameterList ] [ returnType ]
    [ Where genericConstraints ]
    [ statements ]
End Method
Anonymous form
[ modifier ] Method [ < typeList > ] { parameterList | returnType }
    [ Where genericConstraints ]
    [ statements ]
End Method
Abstract form
Abstract Method signature
Trait aliasing form
[ modifier ] Method [ name ] Does traitName . oldName

Parts

modifier
Optional
  • Abstract Specifies that the method must be overridden by a concrete subclass. Only valid inside an Abstract Class or Trait.
  • Override Specifies that the method overrides one inherited from a parent class or trait.
  • Shared Specifies that the method is associated with its surrounding object and not an instance of that object.
name
Required in the standard form.
Not present in the anonymous form.
Optional in the aliasing form.
typeList
Optional. One or more names, separated by commas and enclosed in angle brackets, which become aliases for data types supplied by the code that calls the method. For more information, see Type List.
Not present in the aliasing form, even though the aliased method may be generic.
parameterList
Optional in the standard form. Zero or more variables, local to the method, which are assigned values by the code calling it.
In the anonymous form, A single parameter, required if returnType is not provided.
Not present in the aliasing form, even though the procedure may have parameters.
For more information, see Parameter List.
returnType
Optional in the standard form.
In the anonymous form, required if parameterList is not provided. This defines a type conversion method.
Not present in the aliasing form, even though the aliased method may have a return type.
Syntax
As type
or
In unit
type
Describe
unit
Describe
genericConstraints
Optional. For more information, see Where Clause (Generics).
statements
Optional in the standard and anonymous forms.
Not present in the abstract and aliasing forms.
End Method
Terminates the Method block.
Not present in the abstract and aliasing forms.
signature
The combination of name and parameterList for a standard method, or the parameter or return type for an anonymous method.
traitName
Required in the aliasing form, the name of one trait that the class imports.
oldName
Required in the aliasing form, the name of the method imported via traitName, or an empty string literal ("") if it was anonymous.

Remarks

Do not confuse the End Method clause with the Exit Method statement.

A Method is the only kind of procedure directly callable from a Class, Object, or Library. A Function or Sub procedure can only be called by other procedures.

Standard form

Anonymous form

The anonymous form has two purposes: creating a commonly used method which takes a single argument, or a method which converts its object to a different data type.

Likely the first time you encountered an anonymous method was in the "Hello, world" example. The IO library exposes such a method for outputting a string. This form of Method does not return a value.

Typically, this form looks like the following:

Method ( parameter )

The second purpose for the anonymous form is type conversion. There are times when you need to change the representation of data to interface with an external system. The most common conversion is probably serialization, converting to a string.

Typically, this form looks like the following:

Method As dataType

Abstract form

The abstract form acts like a template. It is used within an abstract class or trait. It is a guarantee that a concrete subclass or the user of a trait will provide its own implementation of the method. Therefore, it cannot contain statements of its own.

Trait aliasing form

You use the aliasing form when you need to rename a method imported from a trait which conflicts with another procedure in your class. You can make a named method anonymous by not providing a new name. The opposite is also possible, allowing you to give a name to what was an anonymous method.

If you want to hide the imported method, the Function Statement has an aliasing form of its own that can turn a public method private.

Examples

See also