Taught in Containers & Strings. One registry serves both backends, so the lists below are the same on each. A method changes its receiver in place; the array::, map:: or string:: function of the same name returns a copy (the pairs).
A spec ends a template splice (${expr:spec}) or a {} placeholder of print or format; format_value(value, "spec") applies one directly. Errors and the : rules: Template strings & format specs.
to_json(x) writes compact JSON, to_json(x, n) indents n spaces per level, from_json(text) reads it back. to_binary and from_binary round-trip the same values. Loading rules: JSON.
Value
JSON
a map with string keys, an array, a string, bool, null
an object, an array, a string, true/false, null
an int, a float
A number that reads back as the same kind. A float is written with every digit it needs to read back exactly.
a map whose keys are not strings
{"$map": [[key, value], ...]}
a char
{"$char": 65}
a float JSON cannot spell
{"$float": "inf"}, "-inf" or "nan"
a class instance
{"$type": "Hero", "$val": {fields}}
a shared_ptr handle, the first to its object
The object, once: {"$id": 1, "$type": "Hero", "$val": {...}}
a shared_ptr handle, every later one
{"$id": 1}
a weak_ptr handle
The same with $ref in place of $id. An expired one is null.
A reusable layout, validated once (binary::layout fields total more than 9223372036854775807 bytes). Field order comes from the arguments, never from a map.
widths
binary::int8, int16, int32, int64, uint8, uint16, uint32, float32, float64, binary::text(n), binary::bytes(n): values that describe an encoding, not types.
binary::bytes(n)
Unpacks to an array<uint8> and packs exactly n bytes.
a width's methods
sizename
a layout's methods
sizecount
load-time checks
A wrong signature, an odd name/width pairing, a non-width where a width belongs, a read(Class, layout) whose class and layout do not match.
regex(pattern) and regex(pattern, flags) make a regex value. Matching is linear in the text: no pattern backtracks. Taught in Regular expressions; the constructs that are errors: no backtracking; bytes against characters: text kinds; load-time compilation: constant patterns.
The character. A backslash before punctuation or a space takes it literally; before a letter that names nothing it is an error.
\xNN
A byte on a string; U+00NN on a utf8_string.
\uXXXX, \u{X}
A code point (its UTF-8 bytes on a string).
.
Any character but a newline (with flag s, any).
[abc], [a-z], [^...], [], [^]
One character of the set, or not of it. - first or last is literal, [] matches nothing and [^] anything.
\d \w \s, \D \W \S
An ASCII digit, word character (letters, digits, _) or whitespace (space, tab, newline, carriage return, vertical tab, form feed), or anything else. Inside a class too.
^, $
The start or end of the text (with flag m, of a line: \n ends one). $ does not match before a final newline.
\A, \z
The start or end of the text, whatever the flags.
\b, \B
A word boundary, or a position that is not one.
(...), (?<name>...), (?:...)
A capture group (numbered from 1 by its opening parenthesis), a named one (also numbered), a group that captures nothing.
x|y
The first alternative that leads to a match. An empty alternative matches empty.
* + ?, {n} {n,} {n,m}
Repetition, as many as possible. A count runs to 1000. A brace that starts no count is a literal brace.
*? +? ??, {n,m}?
Repetition, as few as possible.
(?i), (?-i), (?i:...)
Turns flags on or off to the end of the enclosing group, or inside the group alone (any of i m s x).
The running executable's folder and file, fixed for the process.
app_data_dir(name)
The platform's per-user folder for an app called name, for per-user saves: %LOCALAPPDATA%\name, ~/Library/Application Support/name, $XDG_DATA_HOME/name. A query only.
app_cache_dir(name)
The per-user folder for a regenerable cache: below %LOCALAPPDATA%\name, ~/Library/Caches/name, $XDG_CACHE_HOME/name. A query only.
other platforms (Android)
The host installs its own resolvers for both with engine::app_directory_resolvers.
working_dir()
The working directory.
parent_dir(p)
A normalized parent path, weakly canonicalized, so it can consult the filesystem.
file_name(p)
The lexical last component of a path.
file_data(p)
A map<string, var> about the file or folder the path ladder finds for p (keys below); null when nothing is there, so file_data(p)["modified"] polls without a try.
type_of, except that a typed container gives its canonical tag ("array<int>", not "array"). A reference answers what it refers to. A string is read as a value.
reflect::fields(v)
One map per field: name, type, kind, access, static, from (the declaring class).
reflect::fields order
Base class fields first, then own, in declaration order on every engine and backend; a class's static fields follow its instance fields.
reflect::fields of a C++-bound class
The host's property schema; kind tells a plain field from a "signal" or "observable" member.
reflect::methods(v)
One map per overload: name, arity, static, access, from, params (an array of {name, type, default} maps), sorted by name then arity. Property accessors and constructors are not listed.
s.hp = 42; a typed field converts or raises the direct syntax's error.
reflect::invoke(s, "wound", 5)
s.wound(5)
reflect::bind(s, "wound")
The method as a callable that holds s and keeps it alive: the one spelling of a method taken as a value (Classes). A string, array or map is refused; wrap the call in a lambda.
reflect::call("ns::name", args...)
A call of the global or namespace-qualified function.
reflect::construct("Class", args...)
Class(args): a value; copies are independent.
reflect::construct_shared("Class", args...)
new Class(args): a shared handle, as in spawned.push(reflect::construct_shared(row["type"], row["hp"])).
Every class, script-declared and host-bound, sorted.
reflect::functions()
Every function, namespace-qualified and sorted; no constructors.
reflect::globals()
Global variable names, sorted.
reflect::bases(v)
The base classes in declaration order, empty at a root.
reflect::is_a(v, "Class")
v instanceof Class for a class named at run time: true when v holds an object of the class or of one derived from it; false for any other value, a string included. An unknown class name raises reflect::is_a: unknown class 'Nope'.
reflect::is_cpp_bound(v)
For a class name, whether the host registered it; for a value, whether a C++ object backs it.
reflect::is_enabled(requirements...)
Whether the host granted every named privilege ("filesystem", jai::filesystem, a custom permission name); false for an unknown name (Where files are).
reflect::instances("Class")
The live instances of a class, in creation order.
reflect::generation("Class")
A counter that moves whenever the class is redefined.
What each function does given a value that is neither an instance nor a string (5, an array, null), from Strings are class names. A string that names no class raises reflect::fields: unknown class 'hello', each function under its own name.
Function
Result
fields, bases
[]
has_field, has_method, is_cpp_bound
false
methods, method_arguments, generation, instances
Raises reflect::methods expects a class or class name.
get, set, invoke
Raises reflect::get expects an object or class name.
The URL that answered, after redirects; "" for a response a script built.
headers
A writable map<string, string>. A received answer's names are lowercased and a repeated header is joined with ", ".
header(name)
Reads any spelling of the name; "" when absent.
header(name, value)
Sets a header, replacing any spelling of the name, and returns the response, so calls chain. Raises Response.header: 'N' is not a header name, or its value holds a line break or NUL.
cookies
The Set-Cookie lines (array<string>).
set_cookie(name, value[, options])
Adds a Set-Cookie line, the value percent-encoded. The name is a token.
The formulas behind random, from Randomness: the algorithm, exactly. Every formula is part of the language, so a seed draws the same bits everywhere.
Step
Definition
generator
xoshiro256** 1.0 (Blackman and Vigna): four 64-bit words; a draw is rotl(s1 * 5, 7) * 9.
seeding
The words are four successive splitmix64 outputs from the seed: x += 0x9E3779B97F4A7C15, then z = (x ^ (x >> 30)) * 0xBF58476D1CE4E5B9, z = (z ^ (z >> 27)) * 0x94D049BB133111EB, z ^ (z >> 31).
next_int(lo, hi)
Lemire's method over span = hi − lo + 1: the high word of draw × span, redrawn while the low word falls under (264 − span) mod span.
next_int over the whole int range
One raw draw.
next_float(lo, hi)
fma(u, hi − lo, lo) with u = next_float(), one rounding; a result that rounds up to hi is the float just below it.
shuffle
Fisher–Yates from the last index down, element i swapped with the one at next_int(0, i).
pick
The element at next_int(0, size − 1).
parallel streams
Element i (the chunk, for parallel_reduce) of a loop that captures a generator draws from the stream splitmix64 seeds from mix(draw ^ mix(i + 0x9E3779B97F4A7C15)).
draw, mix
draw is the statement's one draw from the captured generator; mix is the seeding's output step.
math::vec2vec3vec4ivec2ivec3color: value types with component fields (x y z w, r g b a; also widthheightdepth) and component-wise operators. An ivec's zero divisor component raises Division by zero. A default math::color is opaque white; colors mix in OKLab. array<math::vec3> is a typed buffer.
math::dotcrosslengthlength_squarednormalizedistancedistance_squaredreflectprojectperpendicularangle_betweenrotatemath::rotate_aroundmath::anglemath::from_angle (angles in radians); the component-wise math::lerpmath::mixmath::clampmath::minmath::max family with unmixmix_rgbmix_hsvmix_inmix_outmix_in_outmix_out_inunmix_inunmix_outunmix_in_outunmix_out_in
regex(pattern, [flags]), regex::escape(text), regex::match: calls, syntax, flagsi m s x, replacements$1 ${name} $0 $$. Linear time; bytes on a string, characters on a utf8_string; a constant pattern compiles at load.
to_json(x) compact, to_json(x, n) with n spaces per level; from_json(s) rebuilds class instances (through their constructor), chars and non-string map keys (encoding). to_binaryfrom_binaryto_base64from_base64; base64_encodebase64_decode for raw bytes.
random r; (seeded by the system), random r(seed); (the same stream on every platform): next_int(lo, hi) inclusive, next_float() in [0, 1), next_float(lo, hi), next_bool(), pick, shuffle, next_bytes(n), seed(s). A copy replays its draws; state round-trips through every archive.
crypto::random_bytes(n)random_hex(n)random_int(lo, hi): the system's secure generator, never seedable. sha256sha512sha1md5 (hex, _bytes raw), sha256_file(path). hmac_sha256(key, message)hmac_sha512 (hmac_sha256_byteshmac_sha512_bytes raw). equals(a, b) in constant time. password_hash(pw[, cost]) and password_verify(pw, hash): bcrypt as PHP writes it.
atomic<int>atomic<float>atomic<bool>: a host's std::atomic bound by reference into every engine that shares it; never copied. loadstoreexchangecompare_exchange(expected&, desired), fetch_addfetch_sub (int, float), fetch_andfetch_orfetch_xor (int). += -= and ++ -- (int) are single atomic steps; a typed slot is a load.
time::now()engine_elapsed()execute_elapsed()unix_time()unix_ms()date_now(template)utc_now()local_now()date_from_unix(seconds)utc_date(y, m, d, ...)local_date(y, m, d, ...), the value types time::stopwatch and time::date
parallel_for (auto& x : arr) { ... } , parallel_for (int i = a; i < b; i++) { ... } , parallel_transform(arr, f) and parallel_reduce(arr, init, step, combine): deterministic at any worker count; thread_count. A body that writes enclosing state raises parallel_for: body writes enclosing state 'total' at 11:31.
reflect::: type queries, fields and methods by name, reflect::bind(obj, "name"). type_nameis_cpp_boundhas_fieldhas_methodclassesbasesgenerationfieldsinstancesgetsetinvokebindcallconstructconstruct_sharedmethodsmethod_argumentsfunctionsglobalsfunction_argumentsis_enabledtemplate_output_limitscoped_template_output_limitscoped_template_dirs
includeimport (jai::force) import_recheck_interval, under the jai::filesystem privilege; the location builtins root_script_pathroot_script_dircurrent_script_pathcurrent_script_direxecutable_pathexecutable_dirbin_dirworking_dirparent_dirfile_nameresolve_pathapp_data_dirapp_cache_dirfile_data
What a bare engine has.jai::engine::make() alone runs the whole language with these builtins:
a print that concatenates its arguments, and template strings with format specs (format_value)
the builtin container and string methods and their array:: forms
math:: (functions, vectors, colors, wrap_*), regex, and binary:: readers and writers with string::from_bytes
same_object, extend, thread_count, parallel_transform and parallel_reduce, sleep
the location builtins (executable_dir, file_data, resolve_path and the rest)
jai::stdlib::register_all adds the formatted print, format, to_string, type_of, JSON and binary serialization, the string:: functions, to_char, random, time::, crypto:: and reflect::. web:: and spider:: are separate opt-ins.