Types & Values
Pyle is dynamically typed. A variable holds a value, and the value carries its own type. There are no declarations that change runtime behavior and no implicit conversions between unrelated types.
Value tags
Section titled “Value tags”| Type | Literal | Notes |
|---|---|---|
Int |
42, 0xFF |
64-bit signed, wraps on overflow |
Float |
3.14 |
Double precision |
Bool |
true, false |
|
None |
none |
Absence of a value |
String |
"hello" |
Interned, immutable byte string |
Array |
[1, 2, 3] |
Heterogeneous, resizable |
Map |
{a: 1, "b": 2} |
Keys can be strings, ints, and other hashable values |
Range |
1..10 |
Exclusive end |
Tuple |
(1, 2) |
Fixed-size immutable sequence, 2+ elements |
Function |
fn(x) x + 1 |
First-class closure |
StructType |
struct Point(x, y) {} |
Type definition |
Struct |
Point(1, 2) |
Fixed-shape instance |
Bytes |
Bytes([65, 66]) |
Immutable byte buffer |
BytesBuilder |
BytesBuilder() |
Mutable byte writer |
Coro |
Coro(my_fn) |
Coroutine |
Future |
Future() |
Async result handle |
Iterator |
produced by iteration | Internal iteration state |
NativeObject |
produced by bindings | Wrapped C++ object |
typeof returns a string describing a value.
print(typeof(42)) # intprint(typeof(3.14)) # floatprint(typeof("hello")) # stringprint(typeof([1, 2])) # arrayprint(typeof({a: 1})) # mapprint(typeof(fn() => 1)) # functionprint(typeof(none)) # noneFor a struct type, typeof(P) returns a heap reference name such as "HeapRef(12)"; tostring(P) returns "struct {fields}". For a struct instance, typeof(instance) returns "struct" and tostring(instance) returns {field: value, ...}.
Strings
Section titled “Strings”Strings are immutable, interned byte strings. The same string content shares one heap allocation.
let s = "hello"print(s.size()) # 5print(s[0]) # hprint(s.slice(1, 3)) # elprint(s.upper()) # HELLOprint(s.split("l")) # ["he", "", "o"]String indexing is checked at runtime. String comparison with <, <=, >, or >= raises TypeError; only == and != compare strings.
Arrays
Section titled “Arrays”Arrays are reference types with indexed access and mutation.
let values = [1, 2, 3]values.append(4)values[0] = 10print(values) # [10, 2, 3, 4]print(values.slice(1, 3)) # [2, 3]There are no negative indices. Use values[values.size() - 1] for the last element. Out-of-bounds access raises IndexError.
Maps store key-value pairs. Keys can be strings, ints, floats, bools, and other hashable values. Arrays, maps, struct instances, and BytesBuilder cannot be keys.
let person = {name: "Ada", age: 36}print(person.name) # Adaprint(person["age"]) # 36
person["age"] = 37person.city = "London" # dot assignment writes the data key
print(person.has("city")) # trueprint(person.keys())print(person.values())A missing key through brackets raises IndexError. Dot access returns none for a missing key.
Ranges
Section titled “Ranges”Ranges are created with .. and have an exclusive end.
for i in 1..5 { print(i) # 1, 2, 3, 4}
let empty = 5..1Range boundaries must be integers. A float boundary raises TypeError.
Tuples
Section titled “Tuples”A tuple is a fixed-size, ordered, immutable sequence of values, written as zero or more comma-separated values inside parentheses. () is the empty tuple. A single parenthesized value without a comma stays a grouping, so (1 + 2) is 3 and (1) is the int 1; a one-element tuple needs the trailing comma, (1,).
let point = (3, 4)let mixed = (1, "two", 3.5)print(point) # (3, 4)print(point[0]) # 3print(point.size()) # 2print(typeof(point)) # tupleprint((1 + 2) * 3) # 9, grouping() is the empty tuple, (1) is the int 1, and (1,) is a one-element tuple. Indexing is 0-based like arrays, and out-of-bounds access raises IndexError. Tuples are immutable and expose only .size() and .to_array(), so there is no append, insert, or sort.
An array converts to a tuple with .to_tuple() and back with .to_array(). Both copy: the result is independent of the source, so mutating one does not affect the other. An empty array converts to the empty tuple.
The usual purpose is returning several values from a function as one value; index the result instead of writing a struct for a throwaway pair.
fn min_max(arr) { let lo = arr[0] let hi = arr[0] for x in arr { if x < lo { lo = x } if x > hi { hi = x } } return (lo, hi)}
let r = min_max([5, 2, 9, 1, 7])print(r) # (1, 9)print(r[0]) # 1print(r[1]) # 9Tuples compare by identity, so (1, 2) == (1, 2) is false and a tuple cannot be used as a map key. C++ embedding maps them to and from std::tuple and std::pair.
Functions
Section titled “Functions”Functions are closures and first-class values.
fn add(a, b) => a + blet f = addprint(f(2, 3))A function value can be stored in an array or map, passed as an argument, or returned from another function.
Structs
Section titled “Structs”Structs are fixed-shape reference types with fields and methods.
struct Point(x, y) { fn length() => self.x + self.y}
let p = Point(3, 4)print(p.length())Fields must be declared in the struct header. You cannot add a new field after construction.
Equality
Section titled “Equality”== and != compare values:
- Ints and floats compare numerically across types:
1 == 1.0is true. true == 1is false.- Strings compare by content.
- Arrays, maps, structs, bytes, functions, ranges, coroutines, tuples, and native objects compare by identity.
[] == []is false.
print(1 == 1.0) # trueprint("a" == "a") # trueprint([] == []) # false
let a = [1]let b = aprint(a == b) # true, same objectType names as constants
Section titled “Type names as constants”int, float, bool, string, array, map, and bytes are string constants. They are useful with typeof.
let value = 42if typeof(value) == int { print("integer")}There are no int(), float(), bool(), or string() conversion functions. Use toint, tofloat, tonum, tostring, and the string parsing methods.
Primitive types
Section titled “Primitive types”int, float, bool, and none are value types with no methods. Use the global conversion functions:
| Function | Returns | Description |
|---|---|---|
toint(v: any) |
int | none |
Truncate toward zero |
tofloat(v: any) |
float | none |
Widen or parse |
tonum(v: any) |
int | float | none |
Parse a number |
tostring(v: any) |
string |
Display string |
typeof(v: any) |
string |
Type name |
See Built-in Functions for details.