On this page

Same name different frames๏ƒ

๐ŸŸข Beginner ยท Lesson 22

binding_name is a SUB-key - the same name under two different frames is two different addresses. (frame, name) is always the full address; names never collide across frames.

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

Download this collection ยท Source on GitHub

Public surface๏ƒ

the (frame, name) address space

Code๏ƒ

 1"""
 2TIER: beginner (22)
 3GOAL: binding_name is a SUB-key - the same name under two different
 4      frames is two different addresses. (frame, name) is always the
 5      full address; names never collide across frames.
 6SURFACE EXERCISED: the (frame, name) address space
 7"""
 8import melder as md
 9
10
11class UsersRepo:
12    kind = "repo"
13
14
15class UsersApi:
16    kind = "api"
17
18
19def main() -> None:
20    book = md.Spellbook()
21    book.bind(spell=UsersRepo, existence="unique",
22              spellframe="storage", binding_name="users")
23    book.bind(spell=UsersApi, existence="unique",
24              spellframe="web", binding_name="users")
25    conduit = book.conjure()
26
27    repo = conduit.meld(spellframe="storage", binding_name="users")
28    api = conduit.meld(spellframe="web", binding_name="users")
29    assert repo.kind == "repo" and api.kind == "api"
30    print("same name, two frames, two addresses: no collision")
31
32
33if __name__ == "__main__":
34    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