Procedures
Procedure declarations, identifiers, signatures, titles, and descriptions
Sometimes you want to reach out to another set of instructions from the one you're currently working on, or you want to make what your instructions reusable by others. You do that by creating procedures.
Procedure Declarations
A procedure is a series of steps that can be given a name as an identifying label, an input and output type, a title, and a description. Everything but the name is optional.
Identifier
The simplest procedure is a declaration, giving the procedure a name:
making_tea :
Where making_tea in this example is a valid identifier. These are
defined in the usual way; an identifier must:
-
begin with a lowercase letter
[a-z]; then -
any number of additional lowercase letters, digits, or underscores
[a-z0-9_]*.
You'll note that uppercase letters are not allowed. Thus a, book, and
hitchhikers_guide are valid identifiers, but A, Vogon, deepTHOUGHT,
and Constructor Fleet are not. Neither are extended ASCII characters or
higher order Unicode symbols; sorry, you cannot name your procedure
£sterling, valuable as it may be.
Hyphens are also not permitted: make-dinner is not a valid identifier (use
make_dinner instead).
Signature
A procedure may declare a signature indicating the types of its input domain and output range. The types in Technique have two layers: genus, which are the input and output to procedures, and forma, the names given to the basic type elements themselves. These are described fully in Types.
With a signature, a procedure declaration looks like:
poetry_reading : Vogon -> BadPoetry
preparations : (Towel, SubEthaSignalingDevice, Guide) -> HitchHiker
scale_problem : [AlienFleet] -> DinnerForDog
Signatures follow the pattern requires -> provides, where both sides are a
genus. Signatures are optional on procedure declarations, but if present they
must follow this form.
Parameters
Procedures can also name their input parameters as variables. Parameters must be enclosed in parentheses after the identifier name:
create_bypass(a, b) :
bulldoze(c) :
lawsuit(c) : Council -> [Penny]
Parameter names follow the same rules as identifiers: lowercase letters, digits, and underscores.
Procedure Body
Title
A procedure can be given a title. This is the human-readable text that you would expect to see as the name of the procedure, as contrasted to the more program-code-esque name given to the procedure in the declaration.
A procedure title is:
-
a line beginning with the
#marker character; then -
free-form text to the end of line which will be taken as the title.
For example,
calculate_answer :
# How to calculate The Answer
There is an obvious duplication between the identifier used to name the procedure and its title. While at first glance this is a little repetitive, procedure names are used both as targets that can be invoked, and as labels when conducting events and recording the actions they describe. Having a stable machine-readable identifier enables them to be used as part of the address that uniquely identifies them in those cases.
Description
One of the most distinctive features of the Technique language is that it is self documenting. You can write the description of what you are meant to accomplish in a procedure right there in clear text.
attack_insult_source : [AlienFleet] -> DinnerForDog
# Destroy source of insult
We will attack the planet which has been determined to be the source
of the dreadful "I seem to be having this tremendous difficulty with
my lifestyle" insult!
Before going into battle we must make sure that we calculate the scale
correctly, otherwise our fleets would become dinner for a small dog.
Because any procedure (or step) can have a description, there are no comments in the Technique language.
Steps
Steps are the individual actions within a procedure. Dependent steps are numbered and must be completed in order:
1. First step
2. Second step
3. Third step
Steps that can execute in parallel are instead marked with a dash. They can be done in either order, or concurrently:
- Do one thing
- And another
Steps can also have substeps, conventionally indented by 4 characters:
1. First top-level step.
a. First substep in first dependent step.
b. Second substep in first dependent step.
Substep ordinals must be a lowercase letter (not a Roman numeral). Substeps can also be nested under parallel steps:
- First top-level step to be done in any order.
a. First substep in first parallel step.
b. Second substep in first parallel step.
Steps can be organized into sections using Roman numeral headings:
I. First Section
1. Step one
2. Step two
II. Second Section
1. Step three
2. Step four