An execution branch attached to a function is called a "receiver" as it has the special behavior that the terms of any returned axiom can be directly accessed in the branch. This has the effect that, just as a function can be passed parameters when called, it can return parameters on completion. This feature works well with the select operation, as the returned parameters are conveniently named in the declaration header. If a function returns a type other than an axiom, then the return value is accessed using a variable with the same name as the function.
Format
The receiver format consists of the following four components:
flow identifier( parameters ) { flow-body }
The identifier will be a one or two part name depending on where the function being called is located. For a select operation, the first parameter provides the key and cannot be omitted. Additional call parameters in a select operation can set default values of one or more select parameters named in the declaration header..
The following examples demonstrate the receiver format for a variety of function return types starting with axiom.
Select Axiom
stamp-duty2.taq changes the original by attaching a receiver to the "sale_bracket" select function. The receiver performs a calculation using variables with names matching "threshold", "base" and "percent" in the sale_bracket declaration header. These variables are set from the corresponding terms of the selection axiom. Here is the "stamp_duty_payable" flow
{ currency.USD amount }
(
term id,
amount.format(),
bracket = sale_bracket.index() + 1,
string payable = duty.format()
Note one particular behavior of a select function is that the receiver evaluation is skipped if there is no match. Therefore the original branch on success strategy is preserved for when the sale amount is above $5,000.
Basic List
birds3.taq uses a "list_non_blanks" function to filter out blank bird classification categories. The function receives an axiom with terms consisting of a full set of bird categories, many of which are blank. The function returns a string list containing all the non-blank term values. This list is unified with a "list_non_blanks" cursor in the receiver.
Here is the "list_non_blanks" function being applied to the receiver format:
cursor<string> list_non_blanks,
{
? fact text { text += list_non_blanks++ + "," },
?: fact text { text = list_non_blanks++ }
species += text
The flow receiver creates a line of text containing a comma-delimited list of bird characteristics.
Embedded Map
A map can be placed inside a select receiver to make the relationship between the select operation and the map clearly evident. charge-plus-tax.taq provides an example of such a relationship where it determines what percentage tax applies to a sale item appropriate to where the purchase takes place. The country is determined by a mapping of a region code to a country code, for example, code "fr" maps to "FR" for which the tax is 15%