6. Expressions and preparation
Stated scalar expressions include visible integer references, one, checked addition/subtraction/division, lengths, indexed reads, pair construction, and pair projections. There is no zero literal; maintained programs construct zero as one - one using checked subtraction.
Historical language area
The program accepts an integer sequence named reference.
The program accepts an integer named candidate.
The program computes the following result.
First compute the length of the reference. Then iterate from the pair consisting of the difference of one and one using checked subtraction and that computed value using lower-bound narrowing in the reference for the candidate. Before each update, continue only when the second component of the accumulated value is greater than the first component of the accumulated value. Return the first component of the accumulated value.This source documents earlier preparation and search grammar. It is not part of the current callable-Go example set; see the verified examples for source paired with generated Go.
The result is 1. First compute evaluates the length exactly once and publishes that computed value; later textual expressions would otherwise evaluate independently. Preparations are ordered and visible only after declaration inside their containing computation.
Sequence expressions can use an existing sequence, a compatible sequence concept, a checked nested-row selection, an empty sequence, or the sequence consisting of … values. Constructed elements are evaluated and appended left to right. Pair results cannot be prepared.
Indexed reads evaluate their position once and require 0 <= position < length. Addition, subtraction, and division are checked; division truncates toward zero and rejects zero divisors and MinInt64 / -1.
Exercise
Run lower-bound with an empty reference and candidate 3.
Verified solution
The initial pair is [0,0], the pre-update guard is false, and the result is position 0.