Scrolls & Tomes
Scrolls (arrays)
Section titled “Scrolls (arrays)”A Scroll is an ordered, indexable collection.
Scroll heroes is ["Gandalf", "Frodo", "Aragorn"];Scroll numbers is [1, 2, 3, 4, 5];Scroll empty is [];Indexing
Section titled “Indexing”Zero-based indexing:
Chant(heroes[0]); // "Gandalf"Chant(heroes[2]); // "Aragorn"Slicing
Section titled “Slicing”Extract a sub-array with slice syntax [start:end]:
Scroll nums is [10, 20, 30, 40, 50];
Chant(nums[1:3]); // [20, 30]Chant(nums[:2]); // [10, 20] (from beginning)Chant(nums[3:]); // [40, 50] (to end)Slicing also works on strings:
Runestone word is "RuneLang";Chant(word[0:4]); // "Rune"Chant(word[4:]); // "Lang"Mutation
Section titled “Mutation”Scrolls declared with Mutable can be modified:
Mutable Scroll inventory is ["Sword", "Shield"];inventory.push("Potion");inventory.pop();Methods
Section titled “Methods”| Method | Description | Example |
|---|---|---|
.push(val) | Add element to end | list.push("item") |
.pop() | Remove and return last element | list.pop() |
.length() | Number of elements | list.length() |
.contains(val) | Check if element exists | list.contains("x") |
.map(fn) | Transform each element | list.map((Countstone n) => n * 2) |
.filter(fn) | Keep matching elements | list.filter((Countstone n) => n > 0) |
.reduce(init, fn) | Accumulate a result | list.reduce(0, (Countstone a, Countstone b) => a + b) |
.forEach(fn) | Execute function on each | list.forEach((Runestone s) => Chant(s)) |
.find(fn) | First matching element | list.find((Countstone n) => n > 10) |
.sort() | Return sorted copy | list.sort() |
.reverse() | Return reversed copy | list.reverse() |
.flat() | Flatten nested arrays | [[1,2],[3]].flat() |
.join(sep) | Join into string | list.join(", ") |
.indexOf(val) | Index of first occurrence | list.indexOf("x") |
.slice(start, end) | Extract sub-array (method) | list.slice(1, 3) |
Iteration
Section titled “Iteration”Scroll heroes is ["Gandalf", "Frodo", "Aragorn"];
// for-eachOdyssey for hero in heroes is Chant(hero);end of Odyssey
// index-basedOdyssey for i from 0 to heroes.length() is Chant(i + ": " + heroes[i]);end of OdysseyMembership
Section titled “Membership”Chant("Frodo" in heroes); // TruthChant("Sauron" in heroes); // FalsehoodTomes (maps)
Section titled “Tomes (maps)”A Tome is a key-value dictionary. Keys can be strings, integers, or booleans.
Tome stats is {"str": 18, "dex": 14, "con": 16};Tome config is {"host": "localhost", "port": 8080, "debug": Truth};Accessing values
Section titled “Accessing values”Chant(stats["str"]); // 18Chant(config["host"]); // "localhost"Field-style access
Section titled “Field-style access”If the key is a valid identifier, you can use dot notation:
Chant(config.host); // "localhost"Mutation
Section titled “Mutation”Mutable Tome bag is {"gold": 100};bag["gold"] is written as bag["gold"] + 50;bag["gems"] is written as 3; // adds new keyMethods
Section titled “Methods”| Method | Description | Example |
|---|---|---|
.keys() | Array of all keys | stats.keys() |
.values() | Array of all values | stats.values() |
.entries() | Array of [key, value] pairs | stats.entries() |
.has(key) | Check if key exists | stats.has("str") |
.length() | Number of entries | stats.length() |
.remove(key) | Remove and return value | stats.remove("dex") |
.merge(other) | Return merged copy | stats.merge(extra) |
Iteration
Section titled “Iteration”Tome stats is {"str": 18, "dex": 14, "con": 16};
// iterate over entriesOdyssey for entry in stats is Chant(entry); // prints ["str", 18], ["dex", 14], etc.end of Odyssey
// iterate over keysOdyssey for key in stats.keys() is Chant(key + ": " + stats[key]);end of OdysseyMembership
Section titled “Membership”The in operator checks keys:
Chant("str" in stats); // TruthChant("wis" in stats); // FalsehoodNested collections
Section titled “Nested collections”Scrolls and Tomes can be nested:
Scroll party is [ {"name": "Gandalf", "class": "Wizard", "level": 20}, {"name": "Aragorn", "class": "Ranger", "level": 15}, {"name": "Legolas", "class": "Archer", "level": 18}];
Odyssey for member in party is Chant(member["name"] + " the " + member["class"]);end of Odyssey