On this page

Prebuilt registry๏ƒ

๐ŸŸข Beginner ยท Lesson 33

A registry of ready-made same-typed objects. Spell names must be unique per book (probe-proven), so N instances of one class bind as ONE registry spell - the dict is the spell, lookup stays yours.

Before you run๏ƒ

Use the Beginner guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.

Run the saved script๏ƒ

python UX_and_AIX_experiences/01_beginner/33_prebuilt_registry.py
py -3.14t UX_and_AIX_experiences/01_beginner/33_prebuilt_registry.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

collection-as-instance-spell, read permission

Code๏ƒ

 1"""
 2TIER: beginner (33)
 3GOAL: A registry of ready-made same-typed objects. Spell names must be
 4      unique per book (probe-proven), so N instances of one class bind
 5      as ONE registry spell - the dict is the spell, lookup stays yours.
 6SURFACE EXERCISED: collection-as-instance-spell, read permission
 7"""
 8import melder as md
 9
10
11class Palette:
12    def __init__(self, name: str) -> None:
13        self.name = name
14
15
16def main() -> None:
17    book = md.Spellbook()
18    palettes = {p.name: p for p in
19                (Palette("dark"), Palette("light"), Palette("contrast"))}
20    book.bind(spell=palettes, existence="unique",
21              spellframe="ui", binding_name="palettes")
22    conduit = book.conjure()
23
24    registry = conduit.meld(spellframe="ui", binding_name="palettes")
25    assert registry is palettes
26    assert registry["dark"].name == "dark"
27    print("registry spell served:", sorted(registry))
28
29
30if __name__ == "__main__":
31    main()

Check the outcome๏ƒ

The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.

More beginner examples ยท Level guide