Dynamic values
Capy
type any
any is the dynamic type. A value of type any holds a scalar, a map, a list, a function or closure of the current request, or none. Its shape is checked at run time, where the other types are checked by the compiler.
Maps retain insertion order. Replacing a key keeps its position. Deleting and reinserting a key appends it. Lists retain numeric order. Read children with value.name, value["name"], or value[0]. A missing read returns none and does not change the value.
Signed integer inputs use the s64 numeric kind. Unsigned integer inputs use u64. Floating-point inputs use f64. Integer kinds preserve their full 64-bit ranges through assignment, cloning, unit calls, and BRRB. get_type_name reports s64, u64, or f64. Numeric strings remain strings.
An integer-to-float conversion can round values above 2^53. JSON decoding returns integer tokens within the 64-bit ranges as s64 or u64, and other numbers as f64. JSON encoding writes integer kinds as exact numeric tokens.
Arithmetic and comparison operators require matching static scalar types. Convert an any value to the needed scalar type before an operation. The compiler does not provide dynamic arithmetic or equality operators for any.
Use has to test a key. Use get when absence is valid. Use string, bool, s32, s64, u64, or f64 to convert a value.
value ?? default gives default when value is none. Otherwise it gives value, converted to the type of default.
A function that can fail returns a result map: ok, then value on success or error on failure. Use try to handle a result.
Update functions such as set, push, and clear change their target and return it. keys and values return new values.
Assignment and child reads share objects. For example, after var alias := user, alias.name = "Grace" also changes user.name. A child such as var tags := user.tags keeps the same shared identity. Passing or returning an any does not copy it. Use clone(user) for an independent deep copy before a separate edit.
A callable read requires its exact function type. A mismatch traps. Public BRRB replaces a callable with none and keeps its map key or list index. JSON, YAML, and XML reject callables, opaque nodes, cycles, and values beyond the BRRB nesting or node limits. They return an empty string on encoding failure, not partial output.
var user := {"name": "Ada", "tags": ["math"]}
print(user.name, " ", user.tags[0], "\n")
Output
Ada math