⚙️ STARLARK RUNE DIFFICULTY: Adept Structural

The Proxy

Deferring expensive rule evaluations via intermediary structs.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Proxy
ARCANUM SCHOOL: Illusion // Deferment
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// STARLARK PATTERN //
def expensive_target_provider():
    print("Performing heavy target evaluation...")
    return struct(execute=lambda: "Heavy target executed")

def lazy_target_proxy(provider_func):
    state = {"instance": None}
    
    def _get_instance():
        if not state["instance"]:
            state["instance"] = provider_func()
        return state["instance"]
        
    def _execute():
        return _get_instance().execute()
        
    return struct(
        is_proxy = True,
        execute = _execute
    )

# Usage
# The heavy evaluation does not run yet.
proxy = lazy_target_proxy(expensive_target_provider)
# Only upon execution is the underlying artifact conjured.
result = proxy.execute()

Sometimes loading a macro requires querying an external repository or evaluating a deep dependency graph. The Proxy pattern in Starlark shields the build loading phase from these expensive operations by acting as a placeholder. It defers the actual execution (or instantiation) of the target until the precise moment it is required. This lazy-loading technique speeds up the parsing phase, crucial for massive hermetic workspaces.

Runic Tags: #structural #starlark #hermetic