Skip to content

4. Expressions and statements

Draws on: ADR 0001, ADR 0003, ADR 0007, ADR 0011, ADR 0012, ADR 0013, ADR 0016, ADR 0017, ADR 0019, ADR 0020, ADR 0021, ADR 0022, ADR 0023, ADR 0025, ADR 0026, ADR 0029, ADR 0033, ADR 0034, ADR 0035, ADR 0042, ADR 0053, ADR 0059, ADR 0060, ADR 0063, ADR 0112, ADR 0184.

This chapter says what each expression computes and what each statement does. Chapter 2 has their syntax, and chapter 3 the values they work on. Handler dispatch, messages and waiting are in chapter 5, and how an error unwinds is in chapter 6.

A load error, here as in every chapter, is a checker diagnostic: the Script or Library doesn’t load, and parity covers the diagnostic (ADR 0019). Its code is in the catalogue.

  • A body is the code of a Handler, a function or a Lambda. Each Run of it has its own locals. A loop, a branch or a try block has no scope of its own.
  • Its locals are its parameters and every name it binds: a Container root it puts into that isn’t a Script Variable, and the names bound by a let, repeat for each, match, catch or wait for pattern, including Captures (Destructuring), a repeat’s collecting target, a Result Target that isn’t a Script Variable, and an offer’s parameters.
  • They start as Nothing. When a body starts, every local that isn’t a parameter holds Nothing, so reading one before anything is put into it gives Nothing.
  • it is a local of every body, and also starts as Nothing (below).
  • Script level: a Script’s Script Variables, Constants, Handlers, functions and Imports can be used from all of its bodies.
  • Built-ins: the Built-in functions and Constants (chapter 7) can be used everywhere, without an Import.

A Name in an expression or a Container refers to the first of these that has it:

  1. a local of the body, or, in a Lambda, a local it captures (Lambdas)
  2. a Script Variable
  3. a Constant, the Script’s own or imported
  4. a function, the Script’s own or imported, whose bare name is a Function Value (ADR 0025)
  5. a well-known Host Object name, bound by the Host at load (ADR 0016)
  6. a Built-in Constant, such as pi or newline, or a Built-in function

A Name that is none of these is a load error, except as a send’s receiver or a wait for’s from, where it names a Script (chapter 5). So is the bare name of a Handler or a Built-in function, since neither is a value. name(…) calls what name resolves to, so a variable that shadows a Built-in function is called instead of it.

  • No two meanings: a variable (a local, parameter, Capture or Script Variable) that has the name of one of the Script’s own or imported functions is a load error. So is a parameter, pattern binding or Capture that has the name of a Script Variable, a Constant or a well-known object. Import clashes are chapter 7’s.
  • Built-ins may be shadowed: a Script’s own variable, parameter, Capture, Constant, function or Handler, and an Import, may take the name of a Built-in Constant or a Built-in function. The Script’s name wins inside that Script, so a Built-in added in a later language version never stops an existing Script from loading (ADR 0029, ADR 0034).

Note. A local’s scope is its whole body, so put day(d) into day makes day a local throughout, and day(d) then calls it and raises wrong kind. The shadows-builtin Lint warns about every shadowed Built-in (chapter 12).

  • Other positions: a message name after on, send or pass, a Grant name after ask or tell, and an Operation name after to aren’t resolved this way (chapter 5). A send’s bracketed message name is an ordinary expression. me and the target are also chapter 5’s.
  • Shared Handler names: a Script Variable or Constant may have the same name as a local Handler, in either declaration order. A Name in an expression resolves to the Script Variable or Constant; a Command Call or message of that name selects the Handler. This does not relax the clashes with functions or Imports above (#769).
  • Initialisers of a Constant and of a Script Variable may use only literals, Constants declared above them and Built-ins, so evaluating one has no effect. They are evaluated once, in source order, when the Script or Library loads, and an error in one is a load error.
  • A Script Variable declared without = starts as Nothing.
  • A Constant can never be put into, and a Container rooted in one is a load error.

it holds the result of the last statement that set it, in this body:

Statement it becomes
ask … to …, a result-producing tell-block line or Host Command the Operation’s result
send … and wait, or a Command Call sent up the Message Path with and wait the receiver’s reply
a Command Call to a Handler of the Script or of a Library the Handler’s result
a call statement, f(x) or f(x) and wait the call’s result
wait for an event the message, or Nothing on a timeout (chapter 5)
a Join the list of its members’ answers, in start order

A Result Target leaves these rules unchanged. Nothing else sets it. A Join Member leaves it unchanged inside the Join’s body.

Inside a Whose Clause’s condition, it is the chunk being tested, not the body’s it.

  • Source order: an expression’s operands are evaluated left to right, then its operator runs. A call’s arguments, a list’s items, a map’s values and a chunk’s index are evaluated in the order they are written.
  • Errors are raised by the operation that fails, and nothing after it in the expression is evaluated.
  • and and or short-circuit: a and b evaluates b only if a is true, and a or b only if a is false. Each operand they evaluate, and the operand of not, must be a boolean, or wrong kind is raised with expected "boolean".
  • Conditions of if, repeat while and repeat until must be booleans too, so if 0 then … raises wrong kind. A Guard’s must be true for its clause to be chosen (Guards).

a otherwise b evaluates a once and returns that same value unless it is Nothing. Only then does it evaluate and return b, once. False, zero, empty text, lists and maps are present values. The fallback may itself be Nothing. Errors and Limit Faults propagate; otherwise catches neither. Unselected operands consume no Fuel or allocation budget.

The operator is left-associative and has lower precedence than or and all other ordinary binary operators. a otherwise b or c means a otherwise (b or c). Lambdas and Whose conditions keep their whole-expression boundaries: given x: x otherwise d defaults the Lambda result, and the first item of xs whose active otherwise false defaults its condition. Default the selection with (the first item of xs whose active) otherwise d. A Lambda used as a binary operand still requires parentheses.

Both default expressions and optional key reads are permitted in Guards, Whose conditions, Constants, Script Variable initializers and parameter defaults when every operand meets that context’s existing restrictions. Checking includes unselected operands: a lazy branch cannot hide a forbidden call or unresolved name. A Guard’s runtime error or nonboolean result skips its clause under the ordinary rules.

Operator Meaning
=, <>, is, is not equality
<, >, <=, >= ordering
is less than, is greater than, is at most, is at least, comes before, comes after ordering, in words (below)
is in, is not in membership (below)
is a, is not a, can be kind tests
is empty, is not empty emptiness
contains, begins with, ends with search (below)
matches a whole-text match (below)
does not contain, does not begin with, does not end with, does not match a search or match that fails, in words (below)
& joins the text forms of its operands
.. makes a range
+, -, *, /, mod, div, ^, unary - arithmetic on numbers, Quantities and dates
otherwise Nothing defaults
as conversion
of, 's keys and chunks
  • Membership: x is in xs is true when some element of the list xs equals x. x is in r over a range is chapter 3’s. Any other right operand raises wrong kind, with expected "list".
  • Search: a contains b, a begins with b and a ends with b take text on the left, and text or a Text Pattern on the right. Text on the right matches its own Characters, on whole-Character boundaries. They also take Bytes on both sides, and a Bytes needle matches its bytes in a row. Bytes on the left with anything else on the right raises wrong kind with expected "bytes". Any other operand raises wrong kind.
  • matches: s matches p is true when the Text Pattern or text p matches the whole of the text s (Text Patterns).
  • In words: each English comparison spells one above, with its instructions, Fuel and errors (ADR 0075).
    • is less than, is greater than, is at most and is at least are <, >, <= and >=. After is not they give the opposite, so a is not at least b is not (a >= b).
    • comes before and comes after are < and >, for every kind those order.
    • does not contain, does not begin with, does not end with and does not match are not (a contains b), not (a begins with b), not (a ends with b) and not (a matches b).
  • &: the result is the NFC form of the two text forms, joined.
  • ignoring case makes every comparison of two texts that its operator makes compare their simple case foldings, inside lists and maps too, and it applies to every text literal of a Text Pattern the operator uses. After is a, can be or is empty it is a load error, since they compare no text.

Example.

put "Total: " & 42 into label -- "Total: 42"
if "abc" is "ABC" ignoring case then say "same letters"
if "banana" contains "nan" then say "found"
if "ID-0042" begins with <"ID-", digit> then say "an id"
if 3 is in [1, 2, 3] then say "listed"
if "banana" does not contain "x" then say "no x"
if 10 is at least 3 then say "enough"
if "apple" comes before "banana" then say "in order"
  • the k of x and x's k read the Built-in property k if k is one (below), and otherwise the key k. the "k" of x always reads a key, and the (e) of x reads the key that e gives, which must be text, or wrong kind is raised.
  • On a map, a key gives its value, or Nothing if the map has no such key.
  • On a Host Object, id gives its Core-held id. Outside Guards, any other key reads the Host’s property (chapter 9); a key its Object Kind doesn’t define gives Nothing, as a map’s missing key does, and reading it on a disposed object raises object gone. Guards use the pure key rules below and never call the Host.
  • On anything else, Nothing included, reading an ordinary key raises wrong kind with expected "map". So in the b of the a of m, a missing a raises at b. The map Library’s lookup(m, ["a", "b"], default) gives default there instead (chapter 7).

the optional k of x reads a key, even when k spells a Built-in property, target or an ordinal such as first. The key is a Word, Text literal, code points, or a parenthesized expression. the optional of m retains its ordinary key read; write the optional optional of m for its optional form and the optional "of" of m for the key of.

For a computed key, evaluate the key expression and then the receiver once each, in source order. After both finish, require a text key; otherwise raise wrong kind, with expected: "text" and value the key. A receiver expression’s error therefore takes precedence over a previously computed invalid key.

A Nothing receiver returns Nothing. A map returns its value, or Nothing for an absent key. On a Host Object, an optional read is the ordinary read of the same key (above): id gives its Core-held id, any other key reads the Host’s property, with the same Host call and Fuel, giving Nothing for a key its Object Kind doesn’t define, and a disposed object raises object gone. In Guards it follows the same rules as an ordinary Host property read there. So one spelling reads a key whether a Host models a thing as a map or as an object. All other receivers raise wrong kind, with expected: "map" and value the receiver.

Every nullable step must be explicit: the optional b of the a of m can still fail at the ordinary inner read. Computed keys in outer steps still run even if an inner optional read returned Nothing. Optional reads are not Containers and all writes reject them with not a container at the Container’s first token. There is no optional possessive, chunk or call form.

put the optional city of the optional address of customer otherwise "unknown" into city
put the optional ("city") of nothing otherwise "unknown" into city
Property Of Gives
length text, a list, a map, Bytes, an integer range or a Path the number of Characters, elements, keys, bytes, integers or segments
keys a map its keys, as a list, in insertion order
values a map its values, as a list, in the same order
items text its items, as a list of texts
items a list or an integer range its elements, as a list
items a Path its segments, as a list: its Value Path
lines, words, characters text its lines, words or Characters, as a list of texts
bytes Bytes its bytes, as a list of numbers
code points text its code points, as a list of one-code-point texts
elements a Host Object with an Object Collection its members, as a list of Host Objects, read when the property is (the object element contract)

A property of any other value raises wrong kind. the items of s delimited by ";" splits at ; (below).

An Object Element Reference, element 3 of thisPage, and an Element Count, the number of elements of thisPage, read a Host Object’s collection rather than a part of a value. The object element contract specifies them; they are not text/list chunks. the elements of thisPage reads the whole collection as a list, so repeat for each and a Whose Clause over element walk it (ADR 0138).

A Chunk Expression reads part of a value by kind and position: word 2 of line 3 of report (ADR 0011). A chunk word’s singular and plural are the same chunk kind.

Kind Of One chunk is
character text one Character
word text a longest run of Characters that aren’t White_Space
line text the Characters between line breaks
item text the Characters between commas, or between delimiters given by delimited by
item a list one element
item an integer range one of its integers
item a Path one segment: a key as text, or a position as an integer
byte Bytes one byte, as a number
code point text one Unicode scalar value, as text
  • White space: a Character is White_Space when its first scalar is. So the only word in "cat, dog" before the space is "cat,".
  • Line breaks are LF, CR and CR LF, and each is one Character. A line break at the very end of the text doesn’t start an empty last line.
  • Items aren’t trimmed, so "a, b" has the items "a" and " b". Two delimiters in a row give an empty item, and a delimiter at the very end doesn’t give an empty last item.
  • Empty text has no words, lines or items.
  • Any other value raises wrong kind, as word 1 of 42 does.
  • An index is an integer counted from 1, or from the end when negative, so -1 is the last chunk. It may also be an integer range, such as 2..4 or -3..-1, whose ends are read the same way.
  • Ordinals: the first word of s is word 1 of s, and so on to tenth. the last word of s is word -1 of s.
  • Any other index raises wrong kind: a non-integer with expected "integer", and a value of another kind with expected "number".
  • Text: a chunk of text is text. A range of chunks runs from the start of the first to the end of the last, with the delimiters between them, so items 2..4 of "a,b,c,d,e" is "b,c,d".
  • Out of range: reading one chunk of text past its end, before its start or at index 0 gives empty text, so character -4 of "abc" is "". Reading a list, an integer range, a Path or Bytes that way gives Nothing.
  • A Path: a range of items of a Path is a Path, so items 1..-2 of /a/2/b is /a/2.
  • A range’s ends are read as indexes first, each on its own, so characters -1..1 of "abc" is characters 3..1. A range whose first end is after its last is reversed, and gives empty text, an empty list or empty Bytes. Any other range is clipped to the chunks there are: characters 2..10 of "abc" is "bc", characters -5..2 of "abc" is "ab", and characters 5..10 of "abc" is "".
  • Chains: each of reads from the value the chunk to its right gives, so word 2 of line 3 of s reads line 3, then its second word.
  • Chunks of text are text, so arithmetic on them needs as number (ADR 0003).

delimited by d gives the delimiter of every item chunk in its chain, and of the items of. d must be text of one or more Characters, and it matches on whole Characters. A chain with no item chunk is a load error. An empty d raises out of range with field "delimiter".

Example.

put "The quick brown fox" into s
put word 2 of s into w -- "quick"
put characters 2..4 of w into mid -- "uic"
put the last word of s into tail -- "fox"
put word -2 of s into brown -- "brown"
put item 2 of "a;b;c" delimited by ";" into b
put item 5 of "a,b" into gone -- ""
put item 5 of ["a", "b"] into none -- nothing
put word 1 of "12 apples" as number * 2 into dozens -- 24

A Whose Clause, whose c, keeps only the chunks for which c is true (ADR 0074). It may end an Every Head, every K of x, or an ordinal Chunk Expression, the first K of x. It is a whole expression, as a Lambda is, so inside an operand it needs brackets: the length of (every item of xs whose it > 1) (chapter 2).

  • The walk: every K of x whose c and the first K of x whose c walk the Ks of x, the plural property of the chunk kind K (Keys and properties), with the chain’s delimited by if there is one. So they walk the elements of a list, the integers of an integer range, the items, lines, words, Characters or code points of text as texts, and the bytes of Bytes as numbers, and element walks the members of a Host Object’s Object Collection. Any other value raises wrong kind, as the property does. The walk is over a snapshot taken when it starts.
  • it is the chunk being tested, and the body’s own it can’t be read in c. A Whose Clause inside c has its own it.
  • A Whose Key: a Name operand that is c’s first token, not a call and not the start of a Chunk Expression, is the key or property of it with that name, as the possessive whose reads. whose amount > 100 GBP means whose the amount of it > 100 GBP, and whose length > 80 means whose the length of it > 80. A local of the same name isn’t read there. A Reserved Word can’t be a Whose Key, and in brackets the first Name is a plain one: whose (limit) > 3.
  • Other names in c resolve as they do outside the clause. In whose amount > 100 GBP and region is "EU", region is a local, or the load error unknown name if there is none, and the key is it's region.
  • The condition must give a boolean, or wrong kind is raised with expected "boolean", as for if. An error in c is raised in the Run.
  • What c may use: anything an expression may, except a call to anything but a Built-in and a Lambda. A call to a Script or Library function, a Handler or a Function Value, including one through a name that shadows a Built-in, and a Lambda, are the load error not in a whose. Keys and Host Object properties are read as anywhere else.
  • every K of x whose c gives a new list of the chunks for which c is true, in order, or [] if there are none. It is a list for chunks of text too.
  • the n-th K of x whose c gives the n-th chunk for which c is true, and stops there, so c isn’t evaluated on the chunks after it. the last K of x whose c tests every chunk and gives the last one for which c is true. Either gives Nothing when there is no such chunk, for text too.
  • Not a Container: a Whose Clause can be read but not written (Containers).

Example.

put every item of [3, 8, 1, 12] whose it > 5 into big -- [8, 12]
put every item of orders whose amount > 100 GBP into large
put the first item of tickets whose status is "open" and it's owner is empty into next
put the last word of "a bb ccc dd" whose length = 2 into w -- "dd"
put every line of report whose it begins with "WARN" into warnings
put the first item of [1, 3] whose it > 5 into none -- nothing
  • A list literal evaluates its items in order. ...xs splices the elements of the list xs in, and any other value there raises wrong kind with expected "list".
  • A map literal evaluates its values in order, and its keys are the words or texts before each :. A literal with the same key twice is a load error.

A Path Literal makes a Path, and x at p reads through one (ADR 0184, chapter 3).

  • Segments are taken left to right. A Word or quoted text is a key, and digits a position. A literal position 0 or -0, one written with a leading zero such as /007, or one past the position limit, is the load error bad position, so a literal’s position is always written as its text form writes it.
  • A hole ${e} evaluates e and gives one segment: text is a key, and a non-zero integer a position. Any other value raises wrong kind, with expected "text", or "integer" for a number that isn’t one, and a 0 or a position past the limit raises out of range with field "position". A Path or a list there raises wrong kind too: splicing is written ${...e}. The value is never read as Path text, so /${"a/b"} has one key.
  • A splice ${...e} evaluates e, which must be a Path or a list, and adds every segment of it. Each element of a list is checked as a hole’s value is. Any other value raises wrong kind with expected "path".
  • Order: holes are evaluated in source order, and the first error stops the Path. A hole-free Path Literal is a constant.

x at p reads the value p locates inside x, as lookup(x, p) does (chapter 7). p is any expression that gives a Path or a Value Path, checked before any step. Any other value raises wrong kind with expected "path", and a list is checked as lookup checks it: texts and integers, so a 0 step reads as item 0 of does and gives Nothing.

  • Each step: a key reads that key of a map, and a position reads that item of a list, counted as item n of counts.
  • Missing: a missing key, a position out of range, or Nothing reached at any step gives Nothing, and otherwise gives a default: product at /reviews/2/reviewerName otherwise "anon". The empty Path gives x.
  • Wrong kind: a key step at anything but a map, or a position step at anything but a list, raises wrong kind with expected "map" or "list", value the value it reached and path the Path that reached it. So text, a range, Bytes and a Host Object are never stepped into, and Path Access never calls the Host. It is allowed in Guards.
  • Binding: at binds looser than an of chain and tighter than as, and associates left: the reviews of product at /1 as text is ((the reviews of product) at /1) as text.
  • In a call’s arguments: directly in a Command Call’s or Operation call’s arguments, at is Path Access only when a Path Literal follows it, so dock ship at bay keeps its Argument Label (chapter 2). There a computed Path goes in brackets, dock (ship at p), or is spliced, dock ship at /${...p}. Everywhere else x at p takes any operand: put product at p into name. A Lambda’s body, a block Lambda’s statements included, isn’t directly in the arguments, so it follows the general rule.
  • Writing through a Path is a Container, and matching through one is a Path Pattern.

Example.

use decodeJson from json
on review body, i
put decodeJson(body) into product
put product at /reviews/${i}/reviewerName otherwise "anon" into name
put product at /dimensions/width into width
end review
  • f(x, y) calls a function: the Script’s own, an imported one or a Built-in, or a Function Value held in a variable f. The arguments are evaluated left to right, and then the call is made.
  • Named functions run in the caller’s Run, in a new body with its parameters bound. return e gives the result, and a bare return or reaching end gives Nothing. A call that leaves off a trailing parameter with a default passes the default (ADR 0035), and a call with fewer arguments than the required ones, or more than all of them, is a load error. A function never suspends, and reaching a Suspension Point through one is a load error (ADR 0020).
  • Handlers called as functions: a Handler of the Script or of an imported Library may also be called as h(x). It then may not suspend either.
  • Library functions are plain calls too, in the caller’s Run, on the caller’s budgets and Grants (chapter 7).
  • Built-ins never run Script code and never suspend (chapter 7).
  • Function Values: calling a value held in a variable:
    • A value that isn’t a Function Value raises wrong kind with expected "function".
    • A stale one raises function gone before anything else happens.
    • The wrong number of arguments raises wrong arity: for a Lambda, any count but its own, and for a named function, a count outside the range its defaults allow.
    • One whose Home Script is this Script, and that can’t suspend, runs in the caller’s Run, like a named function.
    • One that may suspend, or whose Home Script is another Script, raises would suspend unless it is called as the statement f(x) and wait. A call from another Script is a message to the Home Script (chapter 5).
  • Depth: each call counts toward the call depth limit, and going past it is a Limit Fault (chapter 6).
  • Calls need a name: times(3)(14) doesn’t parse (chapter 2), so a Function Value that a call returns goes into a variable first.

A Lambda makes a Function Value each time it is evaluated (ADR 0025).

  • Its Home Script is the Script whose code it is in. A Lambda in a Library has the calling Script as its Home Script.
  • Captures: a Lambda captures each local of the enclosing body that it names, by value, as it is when the Lambda is evaluated. Inside the Lambda a captured local is read-only, and putting into one is a load error. A Lambda inside a Lambda captures from the one around it.
  • Script Variables aren’t captured. A Lambda reads and writes its Home Script’s Script Variables live, as a Handler does.
  • Parameters are Destructuring patterns, one clause only. An argument that doesn’t match raises no match. The Lambda’s own locals are its parameters and the names it binds itself.
  • Its result: the expression form given r: e gives e. The block form gives the value of its return, or Nothing at its closing end (optionally end given).
  • Control: return returns from the Lambda, never from the body around it. pass and the target are load errors inside a Lambda. it is the Lambda’s own, and try works as anywhere.
  • May suspend: the loader marks a Lambda as may-suspend when its body holds a Suspension Point, and the mark is part of the value. Only the block form can hold one, since wait, ask … and wait and f(x) and wait are statements.

Example.

use map from list
on lambdas
put 3 into k
put given x: x * k into triple
put 4 into k
put triple(14) into answer -- 42: k was captured as 3
put map([1, 2], given n: n + k) into more -- [5, 6]
end lambdas

A Text Pattern is a readable alternative to regular expressions, run on a linear-time matcher with no backreferences and no lookaround (ADR 0007).

  • A <…> literal makes a pattern value each time it is evaluated.
  • Splicing: ( e ) inside it evaluates e then. A Text Pattern is spliced in as an element, and text as a literal element. Any other value raises wrong kind with expected "pattern".
  • Spliced Captures stay Captures. If splicing gives two Captures the same name, or puts a Capture inside a repetition, making the pattern raises can't convert with to "pattern".
Element Matches
a text literal its Characters, in order
character any one Character
characters one or more Characters
digit one Character that is exactly one of the ASCII digits 0 to 9
digits one or more digit
letter one Character whose first scalar is a letter (General Category L)
letters one or more letter
uppercase letter, lowercase letter one Character whose first scalar is in General Category Lu, or Ll
uppercase letters, lowercase letters one or more of the singular
punctuation one Character whose first scalar is punctuation (General Category P)
space one U+0020
spaces one or more space
whitespace one Character whose first scalar is White_Space
word one or more Characters that aren’t White_Space
words one or more word, separated by one or more whitespace
text zero or more Characters
a number an optional -, digits, then optionally . and digits, giving a number
<…> the elements inside it, as one element
a or b a, or else b
  • Sequences: elements separated by commas match one after another.
  • Repetition: one or more of e, zero or more of e and optional e repeat an element, and n e repeats it exactly n times, where n is an integer literal. A count has no limit of its own: every copy counts toward the Text Pattern size limit. For a plural keyword, n counts its singular, so 4 digits is four digit, and 2 words is two words separated by white space.
  • Anchors match an empty position: text start and text end at either end of the text, line start at the start or after a line break, line end at the end or before a line break, and word break at the start and at the end of every word: where the Character on one side isn’t White_Space, and the other side is a White_Space Character or an end of the text. So in "cat, dog" it holds before c, after ,, before d and after g, and never between t and ,.
  • Typed Elements: a number is the only one (ADR 0034). a or an before any other kind is a load error.
  • as number after an element converts its matched text to a number. It is allowed only after an element that can match nothing but ASCII digits, or after a number, so the text always has the number syntax. Anywhere else, as is a load error. Digits past the number limits raise can't convert, as a number does.
  • ignoring case after an element makes its text literals match by simple case folding. Classes keep their meaning.
  • lazily after an element makes it prefer fewer Characters. It is an Advanced Construct (chapter 2).
  • Captures: name: e records what e matched: its text, or its number with a number or as number. A Capture inside a repetition is a load error, and so are two Captures with one name.
  • Priority: a pattern can often match in several ways, and it takes the one it prefers most. An earlier element’s choice counts before a later one’s. a or b prefers a. A repetition, optional and a plural keyword prefer to match more, unless they are lazily, which prefers less.
  • A whole-text match (matches, and a Text Pattern in Destructuring) takes the most preferred way of matching all of the text.
  • A search (contains, when contains, the Match Search and replace) takes the match that starts leftmost, and the most preferred one there.
  • begins with p is true when a match starts at the first Character, and ends with p when one ends at the last.
  • Whole Characters: every element matches whole Characters, and every position is between two.
  • The subject must be text, or wrong kind is raised with expected "text".
  • Use-site ignoring case, on matches, a search operator or a match subject, is the same as putting ignoring case on every text literal of the pattern, spliced ones included.
  • Limits and Fuel: a pattern compiles to a program for a linear-time matcher, whose steps are charged as Fuel, at most the program’s size for each Character (chapter 8). The Text Pattern size limit is in chapter 6.

A Match is the plain map one match gives:

  • text: the matched text.
  • range: the integer range of its Characters, counted from 1. An empty match before Character p has the range p..p-1.
  • captures: a map from each Capture’s name, in the pattern’s order, to its value, or to Nothing if it took no part.
  • ranges: a map from each Capture’s name to its range, or to Nothing.

every match of p in s, the Match Search, gives a list of Matches, left to right. Each search starts where the last match ended.

  • An empty match where the last match ended is skipped, and the search goes on one Character later. This holds after a non-empty match too, which is where the language differs from Python’s and JavaScript’s regular expressions: every match of <zero or more of "a"> in "baab" gives "", "aa" and the "" at the end, and no empty match straight after "aa".
  • It stops when a search finds no match, or when the next search would start past the end of the text.

Nothing holds a last match after matches or contains. Captures bind only through Destructuring or replace (ADR 0007).

replace p in c with e finds the matches of the Text Pattern or text p in the text c, as the Match Search does. For each match, in order, the Captures written in p are put into locals of those names, and then e is evaluated. The result is c with each match replaced by the text form of its e. replace first replaces only the first match. So empty matches are skipped as the Match Search skips them: replace <zero or more of "-"> in "a-b" with "+" gives "+a+b+".

  • The statement puts the result into the Container c. The expression gives it.
  • No match leaves the text as it was.
  • A non-text c raises wrong kind with expected "text".

Example.

put "Smith, Ann" into names
replace <last: word, ", ", first: word> in names with first & " " & last
put replace <"-"> in "a-b-c" with "+" into plussed -- "a+b+c"
put every match of <digits> in "a1 b22 c333" into hits
put the range of item 2 of hits into span -- 5..6
if "ID-0042" matches <"ID-", 4 digits> then say "an id"

A pattern tests the shape of a value and binds its parts (chapter 2 has the syntax).

  • Order: a pattern’s tests run left to right, outer before inner, and stop at the first that fails.
  • All or nothing: a pattern’s names are bound only when the whole pattern matches, and its Guard, if it has one, is true. A failed test binds nothing.
  • Names: a Name matches any value and binds it. The same Name twice in one pattern is a load error. _ matches any value and binds nothing.
  • Literals match a value = to them, so 5 kg matches 5000 g and 1 matches 1.0.
  • List patterns match a list with exactly as many elements, each matching in turn. A final ...rest binds the elements left over as a list, and a final ... ignores them. A rest anywhere but last is a load error.
  • Map patterns match a map that has every listed key, whatever other keys it has. A missing key is a failure, even under _. {name} is short for {name: name}.
  • Text Patterns match a text as a whole-text match, and bind its Captures. After when contains, they search instead.
  • Path Patterns: /a/b is p matches when the value has a value at the Path /a/b, and that value matches p, binding p’s names. Without is, /a/b matches when the Path exists, and binds nothing. Each step is taken as Path Access takes it, but strictly: a missing key or a position out of range fails the match, as a map pattern’s missing key does, so /a is nothing matches only a key a that holds Nothing, and a step through Nothing or a value of the wrong kind fails too. A Path Pattern nested inside another pattern starts from that part of the value. Holes are evaluated when the pattern is tested, as a pin is, and never bind. as after the inner pattern binds the inner value: /a is x as y binds both to the value at /a.
  • Binary Patterns match Bytes (below).
  • The pin ^name matches a value = to the variable name as it stands. It is an Advanced Construct.
  • p as name binds the whole value that p matched.
  • The wrong kind never raises: a list pattern given text, a list pattern given a Path, a Text Pattern given a number, or a Path Pattern stepping into text, simply fails.
  • Errors while testing, such as a splice that isn’t a pattern or a matched number too large to convert, are treated like an error in a Guard: a clause or branch is skipped, and in let, a Lambda parameter or repeat for each the error is raised.

Where a failure goes depends on the pattern’s place:

Place A failure
let raises no match
a Lambda parameter raises no match
repeat for each raises no match
match … when tries the next branch
a Handler head, catch, wait for tries the next clause or branch (chapters 5 and 6)

Example.

let [a, b, ...rest] be [10, 20, 30, 40] -- rest is [30, 40]
let {name: n, age} be {name: "Ann", age: 34, city: "Oslo"}
match reading
when {kind: "wind", speed: s} where s > 30 km/hr then say "gusty"
when /station/tier is "gold" then say "gold station"
when [x, y] then say x & "," & y
else say "something else"
end match

Bytes are matched and built by Binary Patterns, which read fields left to right and never search or backtrack (ADR 0013).

  • The value must be Bytes, or the pattern fails.
  • Literal fields: a number matches one byte of that value, and text matches its UTF-8 bytes. A number that isn’t an integer from 0 to 255 never matches.
  • Integer fields: n: uint16 reads 2 bytes as an unsigned integer, and int8 to int64 read two’s-complement integers. They are big-endian, unless little follows, and big may be written. Each binds a number, and _: uint32 skips its bytes.
  • Bit fields: n: 4 bits reads an unsigned integer, most significant bit first. Their sizes are integer literals, and each run of bit fields in a row must add up to whole bytes, which is checked at load.
  • Byte fields: body: len bytes binds that many bytes as Bytes. as text after it decodes them as as text does, and bytes that don’t decode make the pattern fail.
  • Sizes are an integer literal, a name bound earlier in the same pattern, a pinned variable ^n, or a parenthesised arithmetic expression over those. A negative or non-integer size makes the pattern fail. A bare name that isn’t bound earlier is a load error, which suggests ^n.
  • The rest: a final ... ignores the bytes left over, and ...rest binds them as Bytes, or as text with as text. A ... anywhere but last is a load error. Without one, the fields must use up every byte.
  • Too short: a field that needs more bytes than are left makes the pattern fail.

In operand position, << … >> builds Bytes from its fields, in order:

  • A number is one byte. It must be an integer from 0 to 255.
  • Text is its UTF-8 bytes, and Bytes are copied in as they are.
  • v as uint16, and the other integer types, write v in that many bytes, big-endian unless little follows, as for matching. v as n bits writes v in n bits, and each run of bit fields must add up to whole bytes.
  • v as n bytes takes Bytes of exactly n bytes, and v as n bytes as text takes text whose UTF-8 is exactly n bytes.
  • Errors: an integer too large or too small for its field raises out of range, with the field’s type as field, such as "uint16", "4 bits", or "byte" for a number with no as. A non-integer raises wrong kind with expected "integer", and a Quantity or any other value where a number is needed raises it with "number". A field with no as that isn’t a number, text or Bytes raises it with "bytes". Nothing ever wraps around.
  • Sized fields: v as n bytes needs Bytes, and as text text, or it raises wrong kind with "bytes" or "text". A size that isn’t a number raises wrong kind with "number", and a non-integer one with "integer". A value whose length isn’t the size raises out of range, with field "bytes" or "bytes as text" and the value.

Example.

put << 0x02, 7 as uint32, -3 as int16 little >> into packet
match packet
when << 0x02, id: uint32, x: int16 little >> then say id & " at " & x
end match
put <<0x0D, 0x0A>> into crlf

A Container is a variable, or a chain of chunks and keys rooted in one: item 2 of totals, the age of person. Either may be followed by at and a Path: product at /reviews/2/rating, or product at p (chapter 2 has the syntax).

Built-in properties are read-only: a Container cannot end in or pass through one. Such a target is not a container at its first token, including on a set property target. A quoted key such as the "length" of x or a computed key remains a key; property reads inside computed keys, chunk indexes, delimiters and value expressions remain allowed.

A Whose Clause is never a Container: put 0 into the first item of xs whose it < 0 is a syntax error at whose, and put 0 into every item of xs whose it < 0 one at item. A repeat for each over the positions writes chunks one by one.

  • The root is a local or a Script Variable. A root that is a Constant is a load error. A Built-in Constant’s name as a root makes a local that shadows it.
  • One store: a write reads the root’s value, builds the new value with the named part replaced, and stores it into the root once (ADR 0001). A write that fails leaves the root unchanged.
  • Order: the value being put and the Container’s indexes and keys are evaluated in source order.
  • A chunk of text is replaced by the text form of the value, and the result is normalised to NFC. Writing a word replaces only its Characters, and keeps the white space around it.
  • Padding: writing item k of a text that has n items, with k past n, first appends k - n - 1 delimiters, and one more unless the text is empty or already ends with the delimiter, then puts the value there. A delimiter at the very end ends the last item and makes no empty one (Chunk kinds), so put "e" into item 4 of s gives "a,b,,e" whether s is "a,b" or "a,b,", and ",e" for item 2 of "". A line pads the same way with newline, and any line break at the end counts as its delimiter.
  • Past the end: writing a character or word past the end raises out of range, even just past it, so put "x" into character 4 of "abc" raises. A write never appends: put e after c does.
  • Index 0, a reversed range or an index before the start raises out of range for every chunk kind. A range’s ends are read as for reading, and one at 0 or before the start raises too. field is the chunk kind’s singular word, even after a plural, and value is the index, or for a range the list [from, to] of its ends as written. So put "x" into characters 3..2 of s raises with field "character" and value [3, 2].
  • An item of a list is replaced by the value. Writing past the end pads the list with Nothing. A range of items is replaced by the elements of a list, and any other value there raises wrong kind.
  • A byte is replaced by an integer from 0 to 255, and a range of bytes by Bytes. Writing past the end raises out of range. A value that isn’t a number raises wrong kind with expected "number", a non-integer raises it with "integer", and an integer outside 0 to 255 raises out of range with field "byte" and the value. A range of bytes given anything but Bytes raises wrong kind with expected "bytes".

c at p names the value at the Path p inside the Container c. A write builds the new value as withPath does, and delete removes as withoutPath does (chapter 7, ADR 0136), then stores the root once, as every Container write does.

  • Every writing statement takes one: put … into, before and after, add, subtract, multiply, divide and delete. put "!" after product at /title appends to the value at the Path, as put … after does to a variable. set doesn’t: it writes Host Object properties, and set x at /a to 1 is a syntax error at at.
  • No parents are made: a step through a missing key, Nothing or a value of the wrong kind raises wrong kind with expected "map" or "list" and path. Only the last step may add a key, or write past a list’s end, padding with Nothing. So reading a missing Path gives Nothing, but writing through a missing parent raises.
  • The empty Path names c itself, so put v into c at / is put v into c. delete c at / is the load error can't write, and deleting through an empty Path built with holes raises out of domain, as withoutPath does.
  • Not a Host Object: a step into a Host Object raises wrong kind, as reading does. A Path write never calls the Host.

Example.

put 3 into product at /reviews/2/rating
add 1 to product at /stock
delete product at /tags/1 -- the rest move up
put true into product at /missing/flag -- raises wrong kind: no parent
  • The value under a key is replaced, keeping its place, or the key is added last.
  • Not a map: writing a key of anything but a map raises wrong kind with expected "map". That includes Nothing and a Host Object, whose properties are written only with set, so put, add, subtract, multiply and divide never write one.

Example.

put "a,b,c" into row
put "X" into item 2 of row -- "a,X,c"
put "e" into item 5 of row -- "a,X,c,,e"
put {name: "Ann"} into person
put 35 into the age of person -- {name: "Ann", age: 35}
put [1, 2] into xs
put 9 into item 4 of xs -- [1, 2, nothing, 9]
  • put e into c puts the value of e into the Container c.
  • put e after c and put e before c: if c holds a list, e becomes its last or first element, as one element. If c holds text, the text form of e is joined on, as & does. Anything else raises wrong kind with expected "text".
  • put ...e after c and before splice the elements of the list e into the list c. Either one not being a list raises wrong kind with expected "list".
  • let p be e matches e against the pattern p and binds its names, or raises no match.
  • set c to e writes a property of a Host Object. The computed keys and indexes of c are evaluated first, then e, left to right. Then c is walked from its root, and the property is the last step whose receiver is a Host Object. If no step has one, wrong kind is raised with expected "object". When that step is the last one, the Host’s Set writes e as the whole property (chapter 9). Otherwise the property is read with its Get, e is put into the rest of the path in that value by the rules of put (Writing keys, Writing chunks), and the result is written with one Set. So set the isLocked of the door of me to true is short for set the door of me to merge(the door of me, {isLocked: true}), and a step through a missing key raises wrong kind before any Set. The walk, the Get and the Set are one Host Crossing for where a Stop, cancel or rewind lands (chapter 9) (ADR 0135). For the property, a read-only property is a load error where the object’s kind and the key are known at load, and otherwise raises read only. A well-known Object binding and an Owning Script’s me supply the kind; an unquoted or quoted literal key, including a parenthesized text literal, supplies the key. The check uses the binding’s declaration, without inferring kinds through locals, aliases or property results. A missing property has no Set and is read-only for this check. A computed key that is not a text literal is checked at run time. A disposed object raises object gone. set on a bare variable is a load error.

A set property target may be rooted in a Name, me, it or the target, with only keys and chunks along the path. Rooted in me, it or the target, its path must have a key. Parentheses, quoted keys and computed keys follow the same rules for every root. Intermediate keys and chunks read the receiving Object: for example, set the label of item 2 of it to "Open" works when that item is a Host Object. set item 2 of the tags of it to "new" reads tags, replaces its item 2 and writes tags back.

These property writes do not replace the root binding. Bare me, it and the target, and Containers rooted in them for put, arithmetic, delete or statement replace, are not a container at the target’s first token. Only the result-setting statements described above change it. it and the target do not supply a statically known Object Kind; their property checks happen at run time. The existing Library and Lambda restrictions on me and the target still apply. See ADR 0085.

add e to c, subtract e from c, multiply c by e and divide c by e put c + e, c - e, c * e and c / e into c, with the Container’s indexes and keys evaluated once. So after put "1,2,3" into row, add 1 to item 2 of row raises wrong kind, since a chunk of text is text.

  • A chunk of text is removed. A word goes with the white space after it, or before it if it is the last word. A line or item goes with the delimiter after it, or before it if it is the last one.
  • An item of a list or a byte is removed, and the rest move up.
  • A key is removed from its map.
  • A chunk or key that isn’t there leaves the value as it was.
  • A bare variable is set to Nothing.

if c then … runs its first branch when c is true, and its else branch, if any, when c is false. else if chains test in order.

  • repeat for each p in e evaluates e once and walks a snapshot of it, so changing the variable inside the loop doesn’t change the walk. e must be a list, whose elements are walked in order, a Path, whose segments are walked in order, keys as text and positions as integers, or an integer range, whose integers are walked from its first end up to its second. A range whose ends aren’t integers raises wrong kind with expected "integer", and anything else with expected "list". Each element is matched against p, and one that doesn’t match raises no match.
  • repeat while c tests c before each pass and stops when it is false. repeat until c tests c before each pass and stops when it is true.
  • repeat forever runs until something leaves it.
  • repeat e times evaluates e once. It must be an integer of 0 or more: a non-integer raises wrong kind, and a negative one out of range with field "times".
  • exit repeat leaves the innermost loop, and next repeat starts its next pass. Either outside a loop is a load error.
  • collecting e into v after any head gathers the loop’s results into a new list (ADR 0059). The loop puts [] into v when it starts, before its head is evaluated, so v is a list even when no pass runs, and a while or until condition can read the list so far. At the end of each pass that finishes, e is evaluated and added to v as one element, as put e after v does. A pass that next repeat or exit repeat leaves adds nothing, so next repeat filters. When an error leaves the loop, v keeps what was added before it.
  • The collecting target is a local, bound like a pattern’s name. The body may read it, but writing it there is a load error: a Container rooted in it, a pattern that binds it, or an inner loop that collects into it. A target named like a Script Variable, a Constant, a well-known object, or a name the loop’s own repeat for each pattern binds is a name clash.

match e evaluates e once, then tries each when branch in order. A branch is chosen when its pattern matches e and its Guard, if any, is true, and then its names are bound and its body runs. If no branch is chosen, the else body runs, and without an else, nothing does.

  • when contains <p> searches e, which must be text for the branch to match, and binds the first match’s Captures.
  • ignoring case on the subject makes every text literal and Text Pattern in its branches match case-insensitively.
  • try runs its body. When an Error is raised, the Core searches for a catch before unwinding any failed frame or running cleanup. Patterns and Guards are tried in source order, seeing pre-cleanup state. An accepting ordinary catch runs exited cleanup, discards deeper failed frames, then runs its body with its names bound. Rejecting catches are transparent to outer catches. With no accepting catch, every exited finally runs before the Run ends errored. The offering try’s finally runs after an accepted catch or chosen action, including its ordinary exits (chapter 6).
  • throw e raises e. A map with a text code is raised as it is, with the Core adding at only if it is missing, so throw e rethrows with the original position. Text is short for {code: e}. Anything else raises bad throw.
  • A text literal in a catch head is short for {code: "…"}.
  • What catch never sees: Limit Faults, cancellation and Stop Script, which aren’t errors. finally’s full rules, and which errors each operation raises, are in chapter 6.

A Recovery Offer is a named block declared by an active try, which a caller may choose before failed frames are discarded. A catch … before unwind is a Recovery Catch: its policy runs with the failed continuations retained, sharing the catching body’s actual locals. Falling through declines and tests the next catch, preserving any local or Script Variable writes. An ordinary accepting catch is a barrier; a rejecting catch is transparent.

  • Declarations: offers precede catches. Their plain parameters use ordinary local binding rules and require exact arity, with no defaults, patterns or Argument Labels. Nested tries may shadow offer names. No offer is a Script Value, ambient Library binding or durable handle.
  • Availability: eligible offers belong to protected try scopes still active in this Run’s retained failure chain. Search scopes innermost first, declarations in source order; the nearest same-name offer wins. Local calls, Library frames and same-Run callbacks participate. Foreign Function Value receivers and fresh on error Runs have their own chains. Chapter 7 defines offerAvailable.
  • Choice: choose offer name(args) evaluates arguments left to right, then looks up the nearest name and checks exact arity. Missing names raise offer unavailable with name; wrong arity raises wrong arity, without selecting an outer same-name offer. Argument Errors follow ordinary local handling.
  • Transfer: a valid choice runs exited policy-local cleanup, then exited original failed scopes innermost first. The offering try’s finally remains to protect the action. After cleanup, all action parameters bind atomically in the original owning frame, preserving its other locals and outer iterator state. The sibling offers expire at action entry. Normal action fallthrough continues after the try; return and loop exits use ordinary finally rules. No failed expression or instruction resumes.
  • Policy boundaries: selection cannot suspend. Choice permission is lexical, reset by entering a function or Lambda; helpers can compute values and query availability. A nested policy failure sees only its own bounded failure chain. Chapter 6 defines local handling, escaping policy and cleanup Errors, and cancellation.
  • Action boundaries: actions may suspend only where their surrounding body already permits it; functions remain non-suspending. Recovery creates no Segment boundary, effect rollback or automatic abandonment. Ordinary scope restrictions govern later suspension.

For example, an outer policy chooses a block that preserves the callee’s accumulated rows:

function parseRows lines
put [] into rows
repeat for each line in lines
try
put line as number after rows
offer skip
next repeat
offer useValue value
put value after rows
end try
end repeat
return rows
end parseRows
on parseInput
try
put parseRows(["5", "bad", "7"]) into parsed
catch {code: "can't convert"} before unwind
choose offer useValue(0)
end try
-- parsed is [5, 0, 7]; earlier conversion and accumulation were retained.
end parseInput

The policy can choose skip instead, producing [5, 7]. It can also decline when an offer is unavailable:

function parseRows lines
put [] into rows
repeat for each line in lines
try
put line as number after rows
offer skip
next repeat
end try
end repeat
return rows
end parseRows
on parseInput
try
put parseRows(["5", "bad", "7"]) into parsed
catch {code: "can't convert"} before unwind
if offerAvailable("skip") then
choose offer skip
end if
catch {code: "can't convert"}
put [] into parsed
end try
-- This call offers skip, so parsed is [5, 7].
end parseInput

The same local catch with an explicitly supplied policy callback remains useful when passing policy through the API is convenient:

function parseRowsWithPolicy lines, policy
put [] into rows
repeat for each line in lines
try
put line as number into value
catch {code: "can't convert"}
put policy(line) into decision
if the action of decision = "skip" then next repeat
put the value of decision into value
end try
put value after rows
end repeat
return rows
end parseRowsWithPolicy
function chooseSkip line
return {action: "skip"}
end chooseSkip
function chooseZero line
return {action: "use value", value: 0}
end chooseZero
on parseInput
put parseRowsWithPolicy(["5", "bad", "7"], chooseSkip) into skipped
put parseRowsWithPolicy(["5", "bad", "7"], chooseZero) into replaced
-- skipped is [5, 7]; replaced is [5, 0, 7].
end parseInput

The function may live in a Library while the policies live in the calling Script and are passed as Function Values. Each policy must be non-suspending and callable in this Run, with its Home Script the caller’s Script. This is a useful beginner alternative, but every API between caller and parser must explicitly forward the policy when the parser is deeper in the call chain.

return e ends the body with the value of e, and a bare return ends it with Nothing, as reaching end does. In a Handler, that value is the Handler’s result, and the reply to a send … and wait (chapter 5).

  • A Command Call name args calls a Handler of the Script, or else an imported one, in this Run, with the arguments evaluated left to right, and puts its result in it. With no such Handler, it is a send of the message along the Message Path, which doesn’t wait (chapter 5).
  • A call statement f(x) makes the call and puts its result in it.
  • and wait: a Command Call to a Handler that may suspend must end in and wait, and one to a Handler that can’t must not. Both are checked at load. f(x) and wait is allowed on any Function Value, since the loader can’t know which one a variable holds (ADR 0025).
  • ask g to op args calls the Operation op of the Grant g, with the arguments evaluated left to right, and puts its result in it. A Result Target, into x, also receives the result. and wait must be written exactly when the Operation is declared suspending, and both are checked at load against the Grant (ADR 0012).
  • tell g to op args calls a fire-and-forget Operation, and drops its result. tell on any other Operation is a load error.
  • Argument Labels: an Operation that declares labels (chapter 9) may be called with them between its arguments, in any of these forms: ask world to move "pass" to "red hangar" is the same call as ask world to move "pass", "red hangar", which stays valid. A labelled call writes the declared labels in order, one before each argument after the first. It may leave out any Optional argument after the first along with its label, and that argument is Nothing: with labels = ["on", "with"], tell sound to play "rain" with opts is tell sound to play "rain", nothing, opts. The argument count is checked first, as wrong argument count. Then the labels are matched left to right, each to the first declared position after the previous argument’s with that word, and a label with no such position, one that skips a required argument, or any label on an Operation that declares none, is wrong labels at that label (ADR 0160). That is a rule of its own, so a literal argument that also breaks its Shape is wrong argument as well. Labels change nothing at run time (ADR 0115).
  • A tell g block calls each line’s Operation of g in order, as the one-line call that its Operation’s declared mode allows: tell g to op args for a fire-and-forget Operation, and ask g to op args for any other, so an answer lands in it (ADR 0063). A result-producing line may take a Result Target before any and wait, with the same meaning as on ask. A fire-and-forget line with one is wrong mode at its Operation name. A line ends in and wait exactly when its Operation is declared suspending. The block is nothing more than those calls: a later line’s arguments see the it an earlier line left, and in a Join’s body a line with and wait is a Join Member. A mismatched and wait is wrong mode, and an Operation g doesn’t declare is unknown operation, both at the line’s Operation name. A line may write its Operation’s labels (move "pass" to "red hangar").
  • Grants, Shapes, costs and failures are in chapter 5 and chapter 9. say x is short for tell console to write x (chapter 12).

A Result Target, into name, keeps a call’s answer in a named place as well as it (ADR 0114). It may follow an ask, a result-producing tell-block Operation line, a Command Call, a call statement (f(x) into answer, also with and wait), or send … into answer and wait in either receiver order, including computed names and spreads.

  • The Name: it is written as put it into name would write it: a Script Variable if one exists, otherwise a body local. Existing parameters are writable locals. Constants, captured locals in a Lambda and collecting targets have the same write restrictions as put. it and me aren’t Names here, so they are syntax errors, as are chunks, keys and any other Container beyond a bare Name. A target binds throughout its body, including before the call and outside a Join’s branches and loops; a new local starts as Nothing.
  • Timing: outside a Join Member, once the call succeeds, it and the target receive the same value with no intervening Suspension Point or instruction that can raise a Script Error. An error in evaluating or executing the call, timeout, revocation, cancellation or abandonment does not assign its result to either. This doesn’t undo writes made by the called code itself, and ordinary catch and Segment rollback rules still apply.
  • No implicit waiting: a target adds no suspension and changes neither resolution nor the existing and wait checks. A Command Call that resolves to a local or imported Handler takes its result, including Nothing on a fall-through return. A Host Command takes its immediate or suspending Operation’s result; a fire-and-forget one, including say, has no result and is wrong mode at the command name. A Command Call sent up the Message Path, or an explicit send, needs and wait to have a target: without it, the load error is missing and wait at the command name or send. It never starts a fire-and-forget send and assigns Nothing as a substitute.
  • Joins: a member’s target is registered when that member starts, and is written only when the whole Join succeeds, as chapter 5 specifies. An immediate call inside a Join remains an ordinary call and writes its target at once.
  • Statement only: a target doesn’t turn a call into an expression and cannot appear inside an argument or put expression. and wait stays last.

send, wait, wait for, the Join, veto and pass are in chapter 5.

Catch patterns and Guards run before deeper finally blocks. A Recovery Catch keeps these same Guard restrictions; offerAvailable can test an eligible offer in its Guard (chapter 7).

A Guard is the where condition of a Handler Clause, a match branch, a catch clause or a wait for branch (ADR 0021).

  • When: it is evaluated after its pattern matches, with the pattern’s names bound.
  • What it may use: literals, operators, conversions, Chunk Expressions, keys and Built-in properties, Path Literals and Path Access, Text Patterns, Built-in functions and Built-in Constants. It may read the pattern’s names, the body’s locals, Script Variables and a Host Object’s id, and compare Host Objects by identity.
  • What it may not use: a call to anything but a Built-in, including a Script or Library function, a Handler and a Function Value (a call through a name that shadows a Built-in is one), a Lambda, and a Host Object property other than id where the object is known at load (me, the target or a well-known Object name). Any of these is a load error. A computed key on such an object is allowed only when it is the text literal "id". So a Guard never runs Script code, never calls the Host and never suspends.
  • Dynamic keys: a key of a value whose kind is not known at load is evaluated without a Host call. Maps use their ordinary key lookup; an Object permits only id. Any other Object key raises wrong kind with expected "map", charged as the key instruction, and skips the clause as any Guard error does. This applies to disposed Objects too, and to literal and computed keys.
  • Its result: the clause is chosen only when the Guard gives true. false skips it. So does any other value and any error, which is never raised into the Run. try, on error and the Run’s report don’t see it, and the Trace records the skip.

Example.

try
add part as number to runningTotal
catch {code: "can't convert", value: v} where the length of v < 20
tell log to write "skipping " & v
end try

Evaluate Interpolation Holes left to right, converting each result with & before evaluating the next hole. Insert each result once; its newlines are not indented and its ${…} text is not interpreted again. Constants, Script Variable initializers, parameter defaults and Guards apply their existing expression restrictions inside every hole. A hole-free literal is a constant; a literal with holes is eligible in an initializer exactly when its expressions are eligible. Chapter 8 fixes lowering and charges.

None.