list, dict, str
These three namespaces declare methods — procedures whose first parameter is named self. Both call forms type-check, but only one builds:
scores.contains(4); # method form ✅list.contains(scores, 4); # namespace form ⛔ "undeclared list 'list'"Use the method form everywhere.
Language-level syntax for these types is in Lists and dicts; this page is the API surface.
scores.add(item: T) -> void ✅ # data_addtolistscores.contains(item: T) -> bool ✅ # data_listcontainsitemscores.length() -> num ✅ # data_lengthoflistscores.clear() -> void ✅ # data_deletealloflistscores.indexOf(item: T) -> num ✅ # data_itemnumoflistscores.show() -> void ✅ # show the list monitorscores.hide() -> void ✅scores.insert(item: T, idx: num) ✅ # data_insertatlistscores.remove(idx: num) -> T ✅ # reads the item, then deletes itscores.merge(addition: list<T>) ✅ # appends every itempublic scores: list<num> = [3, 1, 4];
proc tally() -> void { scores.add(7); private n: num = scores.length(); private where: num = scores.indexOf(4); # 0 if absent if (scores.contains(1)) { ... }}T binds from the receiver, so scores.contains("x") on a list<num> is a type error.
insert, remove and merge
Section titled “insert, remove and merge”scores.insert(9, 1); # 9 becomes the first itemprivate gone: num = scores.remove(1); # delete item 1 and keep its valuescores.remove(1); # a discarded result emits only the deletescores.merge(other);scores.merge(scores); # safe: the count is read once, up frontmerge takes a declared list or a slice, not a literal. On a list<Struct>, insert and remove work and merge does not; see Struct lists.
List slices lower through a stdlib procedure, sliceInto, which cannot be called directly. Write dst = xs[start:stop:step]; instead.
stock.contains(key: K) -> bool ✅stock.length() -> num ✅stock.keys() -> list<K> ✅ # live and read-onlystock.values() -> list<V> ✅ # live and read-onlystock.merge(addition) -> void ✅ # shared keys take the new valuekeys() and values() read the dict’s column directly, so writing to one is a build error: it would put the columns out of step. Store one in a list to get a copy you can change:
for (name, stock.keys()) { looks.say(name, 1); }
private names: list<str> = stock.keys(); # a copynames.add("extra");merge only takes a declared dict, not a literal.
The rest of a dict is language syntax rather than a method:
public stock: dict<str, num> = {"apple": 2, "banana": 5};
private n: num = stock["apple"]; # ✅ readstock["cherry"] = 7; # ✅ write — appends if the key is newstock["apple"] += 1; # ✅ compound assignment
for ((name, count), stock) { # ✅ iterate both columns report(name, count);}greeting.contains(substring: str) -> bool ✅ # operator_containsgreeting.slice(start: num, stop: num, step: num = 1) -> str ✅ # what s[a:b:c] callsThat is the whole namespace so far. An any value has these methods too, so answer.contains("y") type-checks without a Str() cast.
Other string operations live elsewhere:
len(greeting); # prelude — operator_lengthgreeting[1]; # 1-based indexing — operator_letter_ofgreeting + name; # operator_joinf"{greeting} {name}"; # interpolation, also join
for (letter, greeting) { ... }There is no split, replace, toUpper, or trim. Slices cover substrings, see Slices. Build the rest by walking characters:
proc countChar(s: str, target: str) -> num { private n: num = 0; for (c, s) { if (c == target) { n += 1; } } return n;}