DEVELOPMENT EDITION · 769442725406
Vibe syntax
On this page

Vibe expressions

An expression computes a statically typed value. It cannot perform arbitrary Python object protocols, dynamic attribute lookup, or implicit truth conversion. The precedence table determines grouping; the shared expression rules determine the checks and meaning after typing.

Arithmetic

+, -, *, %, //, and ** are the typed arithmetic of their operands' type. Unary + and - keep the operand's type. Signed integer overflow does not wrap: it is a proof obligation, as are a zero divisor, negating or dividing the smallest value by −1, and an exponent out of range. Modular arithmetic wraps at its type's modulus.

/ is Python's true division: its result is a float even for integer operands, so 7 / 2 is 3.5. // is floor division and % its remainder, as in Python: -7 // 3 is −3 and -7 % 3 is 2, so a nonzero % result has the divisor's sign. Of floats they are CPython's too (-7.5 // 2.0 is -4.0, -7.5 % 2.0 is 0.5, from the exact remainder), and so is ** with a float base or exponent (2 ** 0.5, x ** 3): the C library's pow, as CPython's, to the last digit. An int meeting a float in arithmetic or a comparison is converted to a float, as Python converts it, where the annotations say which operand is which; otherwise write float(n). For an integer quotient, use //; for a real one, /. verada's div(a, b) and rem(a, b) are Ada's integer / and rem, which truncate toward zero: div(-7, 2) is −3 and rem(-7, 2) is −1 (a translation from Vada or Varc writes them).

+ of two strings joins them, as in Python: image(a) + "!".

~x, x << n and x >> n of an int are Python's: ~x is -x - 1, x << n is x * 2 ** n (its overflow a proof obligation), and x >> n is x // 2 ** n, rounding down (-9 >> 2 is −3, and a count of 63 or more gives 0 or −1). A negative count, Python's ValueError, is a precondition's failure.

&, |, and ^ of ints are Python's bitwise operations, in two's complement as Python's ints behave (-13 & 6 is 2); of Booleans and modular values, the Boolean and modular operations; and of sets their intersection, union and symmetric difference (sets). @ is the matrix product of two Array matrices (and m.T their transpose), lowered as APL's +.× and ⍉; see the APL chapter.

Boolean values and comparisons

and, or, and not take Boolean operands. and/or short-circuit: evaluate the second operand only when required. Their result is Boolean; do not use value or fallback with a number, string, list, or other object as Python's truth-value selection idiom.

The ordered comparisons are <, <=, >, >=, ==, and != for types providing the appropriate operation: numbers, enumerations, str (by code point, as Python compares strings), tuples (by their first components that differ), and sets (by inclusion). Chained comparisons such as 0 <= index < len(values) mean the conjunction of the adjacent comparisons with short-circuiting. Supported ordinary function expressions obey Verada's purity rules; do not rely on a mutating call in a middle operand.

is None and is not None test whether an owner is null, or whether an optional value has a value. They are the only uses of is: Vibe's objects are values, so == compares them, and there is no object identity to test.

x in (a, b, c) tests membership in the listed choices when the expression can be typed. x in range(a, b) tests a <= x < b, Ada's X in A .. B - 1. x in a tests membership in an array, a list or a set, and in a dictionary's keys; of two str values, whether the first occurs in the second. not in negates the test.

The conditional expression is chosen if condition else alternative. condition must be Boolean; the two result branches must have a compatible expected/result type. Only the selected branch is evaluated. There is no Python match expression; match is a statement.

Calls, construction, and attributes

A call names a visible typed function; its arguments, by position or by name, are checked against the profile and the precondition. A function is not a value to store or pass.

A class call constructs or converts: dataclasses take keyword field values, array classes take their aggregate, and scalar classes convert.

object.field selects a declared component or supported operation. T.first and T.last denote bounds. array.shape[k], with a nonnegative literal dimension number k, is that dimension's length. Any other attribute name is a field, a method, or a name of an imported unit.

Indexing

Operand value[index] means
List/vector Element at zero-based position; converted to the library's one-based index
Text/string Character at zero-based position in the supported text/string view
Dictionary Value for the actual key; membership/precondition must establish existence
Tuple Component selected by a literal zero-based position
Fixed array declared with index=T Element at the actual index value of T
Fixed size/shape array Element at the declared zero-based index/indices
Runtime-bounds rank array Element at zero-based position relative to each dimension's bounds

Multiple indices use one subscript: matrix[i, j]. Every index and key check is a proof obligation. A negative index written as a number counts from the end of a list or a string, as Python's does: xs[-1] is xs[len(xs) - 1], which must be present (a tuple's t[-1] is its last item). The sequence must be a name (or a field of one), since it is read twice, and its type known from the annotations (B0401 asks for them otherwise; a dict's d[-1] is its key -1). A negative position computed at run time fails its index check rather than counting from the end.

A slice, xs[a:b], is the elements from position a up to (not including) b of a list (a new list), a string (a new str) or a one-dimensional array indexed by position (a slice of the array). Its bounds are Python's: a missing one is the start or the end, a negative one counts from the end, and one beyond the length is the length, so a slice is never out of range (xs[3:100] of a five-element list is its last two, xs[4:1] is empty). An array's slice may be assigned a value of the same length; a list's or a string's may not (B2001). A slice with a step, xs[::2] or s[::-1], is Python's too, of a named list or string whose type the annotations give: the elements at positions a, a + k, ... before b (backwards from the end for a negative step), a new list or string. The step is a number written in the slice; one known only at run time is B0401, whose fix is a loop over range(a, b, k).

Supported builtin-shaped operations

Form Meaning and limit
abs(x) Typed numeric absolute value, including the smallest-value overflow check
min(a, b), max(a, b) Select one of two ordered values
min(xs), max(xs), sorted(xs), list(xs) Of a list, a generator or a comprehension: its first least or greatest element (requiring one, Python's ValueError), or a sorted copy (lists); sorted(s) of a set is its elements in order; no key= or default=
round(x), round(x, n) Of a float: the nearest int, a half to the even one; x at n digits, from its exact value, as CPython's
divmod(a, b) The tuple (a // b, a % b) of names or numbers
ord(c), chr(n) A one-character str's code point, and the str of a code point
int(x) Convert an integer type or truncate a real toward zero into Integer; range checked
int(s) Of a str: Python's reading (spaces around, a sign, digits with single underscores between them); requires is_int(s) (from verada import is_int), where Python raises ValueError; a literal is read at compile time
repr(x) A str quoted and escaped as Python's repr; a list's, dict's, set's or tuple's, its elements' reprs (['a', 'b']); another value's str
format(x, spec) Python's format of an int, float or str by a literal spec, as an f-string field's
~x, x << n, x >> n Python's bit operators on int (above)
float(x) Convert to Long_Float
div(a, b), rem(a, b) Ada's integer quotient and remainder, toward zero (from verada import div, rem)
len(x) Array dimension length, the type's Length, a class's __len__, or an Enum class's member count
str(x) Supported image converted to text, a list's, dict's, set's or tuple's as Python's repr of it (print(xs) too), a class's __str__ (else its __repr__, a dataclass's Python's)
sum(xs), sum(xs, start) Sum from zero, or after start, of a list, a list written out (sum([1, 2, 3])) or a comprehension; of floats compensated, as CPython's is, and proved where the values have a bounded type (type Reading = Annotated[float, Ge(-1e6), Le(1e6)], list[Reading]) and the count is bounded
plain_sum(xs) A float sum left to right from 0.0, rounding at each step: Ada's 'Reduce ("+", 0.0)
sum(expr for ...) Supported one-clause generator reduction, over a range with a step too
all(predicate for ...), any(predicate for ...) Quantified/pipeline condition over a supported iteration domain
copy(x), move(x), deref(x) Explicit value-copy/ownership/dereference helpers; see sharing

all and any take a generator expression, or a list[bool]. Other Python builtins are not Vibe's; a function the program declares with such a name is an ordinary function.

Strings and printing

str values are immutable texts of Unicode code points, copied by assignment. text[i] reads a character (a one-character str), len counts them, ==, !=, <, <=, > and >= compare texts by code point, + joins two, s * n repeats one (empty when n <= 0), and t in s asks whether t occurs in s. Build text with + or an f-string.

These methods are Python's, with Python's results:

Method Result
s.find(t), s.index(t) The first position of t (from 0); find gives −1 when there is none, index requires t in s
s.count(t) How many times t occurs, not overlapping, from the left
s.startswith(t), s.endswith(t) Whether s begins, or ends, with t
s.replace(old, new) Every occurrence of old, from the left, replaced
s.upper(), s.lower() CPython's case mapping of each character, of all of Unicode ("ß".upper() is "SS"); a character whose case is several characters other than ß is kept as it is
s.capitalize(), s.swapcase(), s.title() The first character upper case and the others lower; each case swapped; each word's first letter upper case and its others lower
s.ljust(w), s.rjust(w), s.center(w), s.zfill(w) Padded to width w with spaces (or the one-character fill given), on the right, the left or both as CPython centres; zfill with 0s after a sign
t.format(a, ...) Of a literal template: its {}, {0} and {:spec} fields, as the f-string it means
t % (a, ...) Of a literal template: printf's %d, %5.2f, %-4s, %r, %% and the rest, as the f-string it means
s.isdigit(), s.isalpha(), s.isspace() Whether s is nonempty and each character is one, as CPython classes the characters of all of Unicode
s.strip(), s.lstrip(), s.rstrip() Without whitespace at both ends, or one; with an argument, without those characters
s.split(sep), s.split() A list[str] of the pieces between separators, or of the runs of non-whitespace; sep must not be empty
sep.join(xs) The texts of a list[str] with sep between them

Their contracts give what proofs need: lengths (len(s * n), len(s.upper()), the pieces of a split, which joined with the same separator give s back in length), positions and membership. Only memory limits a str: making one longer than memory holds is a Storage_Error. So no string operation needs anything of the program's lengths: +, *, upper, count, split, replace and join take any texts.

print(a, b, ...) is a statement call that emits supported value images separated by one space and ends with a newline. print() emits just the newline. end= with a string literal writes that string instead of the newline, so print(x, end="") ends no line (Ada.Text_IO's Put); sep= with a string literal writes it between the values instead of a space; print takes no other keyword argument (B0401). Values print as Python prints them: integers with no leading blank, Booleans as True/False, floats in Python's shortest form, Enum members as Colour.RED, text as its characters, a list, a dict, a set or a tuple as Python's repr, a dataclass as Python's repr (Point(x=1, y=2)) and a class with __str__ as that gives.

F-string fields print the same way. Text can exhaust storage even when every check is proved; running out of memory is not a proof obligation.

Source evidence: expression lowering, surface operation resolution, and images.