On this page

Meld address forms๏ƒ

๐ŸŸข Beginner ยท Lesson 26

THE ADDRESS LAW (run-proven + doc-canon): every spell lives at one (frame_key, binding_key) address - frame_key is your spellframe, or the spell's normalized name if you gave none; binding_key is your binding_name, or the default slot. Human callers use a quoted spell name; machine callers use an explicit spell_id. A categorized registration also has a complete (spellframe, binding_name) address. A name alone does not supply a custom spellframe.

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/26_meld_address_forms.py
py -3.14t UX_and_AIX_experiences/01_beginner/26_meld_address_forms.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

meld("SpellName"), meld(spell_id=...), meld(spellframe=..., binding_name=...)

Code๏ƒ

 1"""
 2TIER: beginner (26)
 3GOAL: THE ADDRESS LAW (run-proven + doc-canon): every spell lives at
 4      one (frame_key, binding_key) address - frame_key is your spellframe,
 5      or the spell's normalized name if you gave none; binding_key is
 6      your binding_name, or the default slot. Human callers use a quoted
 7      spell name; machine callers use an explicit spell_id. A categorized
 8      registration also has a complete (spellframe, binding_name) address.
 9      A name alone does not supply a custom spellframe.
10SURFACE EXERCISED: meld("SpellName"), meld(spell_id=...),
11                   meld(spellframe=..., binding_name=...)
12"""
13import melder as md
14
15
16class BillingService:
17    def total(self) -> int:
18        return 42
19
20
21class LedgerService:
22    pass
23
24
25def main() -> None:
26    book = md.Spellbook()
27    # default address: ("billingservice", default slot)
28    spell_id = book.bind(spell=BillingService, existence="unique")
29    # explicit address: ("finance", "ledger")
30    book.bind(spell=LedgerService, existence="unique",
31              spellframe="finance", binding_name="ledger")
32    conduit = book.conjure()
33
34    by_name = conduit.meld("BillingService")
35    # Explicit machine form: SHA identity never shares the human string slot.
36    by_id = conduit.meld(spell_id=spell_id)
37    assert by_name is by_id
38    print("quoted name and explicit ID resolve the same spell:", by_name.total())
39
40    ledger = conduit.meld(spellframe="finance", binding_name="ledger")
41    assert isinstance(ledger, LedgerService)
42    print("framed spell answers at (frame, name)")
43
44    try:
45        conduit.meld("LedgerService")
46    except KeyError as err:
47        print("name-derived key misses a framed bind:", err)
48
49    try:
50        conduit.meld(binding_name="ledger")
51    except ValueError as err:
52        print("binding_name alone refused:", err)
53
54
55if __name__ == "__main__":
56    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