On this page
Named bindings๏
๐ข Beginner ยท Lesson 04
Two implementations of one shape, told apart by binding_name - the beginner door into disambiguation (spellframes come later).
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/04_named_bindings.py
py -3.14t UX_and_AIX_experiences/01_beginner/04_named_bindings.py
Public surface๏
md.Spellbook, md.Existence, binding_name= on bind/meld
Code๏
1"""
2TIER: beginner (04)
3GOAL: Two implementations of one shape, told apart by binding_name -
4 the beginner door into disambiguation (spellframes come later).
5SURFACE EXERCISED: md.Spellbook, md.Existence, binding_name= on bind/meld
6"""
7import melder as md
8
9
10class PostgresStore:
11 kind = "postgres"
12
13
14class SqliteStore:
15 kind = "sqlite"
16
17
18def main() -> None:
19 book = md.Spellbook()
20 book.bind(
21 spell=PostgresStore,
22 existence="unique",
23 binding_name="primary",
24 )
25 book.bind(
26 spell=SqliteStore,
27 existence="unique",
28 binding_name="local",
29 )
30 conduit = book.conjure()
31
32 primary = conduit.meld("PostgresStore", binding_name="primary")
33 local = conduit.meld("SqliteStore", binding_name="local")
34 assert primary.kind == "postgres" and local.kind == "sqlite"
35 print("named bindings resolved:", primary.kind, "+", local.kind)
36
37
38if __name__ == "__main__":
39 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.