Add Scheme forms: named let, letrec, dynamic-wind, three-tier equality
Spec (eval.sx, primitives.sx): - Named let: (let loop ((i 0)) body) — self-recursive lambda with TCO - letrec: mutually recursive local bindings with closure patching - dynamic-wind: entry/exit guards with wind stack for future continuations - eq?/eqv?/equal?: identity, atom-value, and deep structural equality Implementation (evaluator.py, async_eval.py, primitives.py): - Both sync and async evaluators implement all four forms - 33 new tests covering all forms including TCO at 10k depth Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -132,6 +132,27 @@ def prim_eq(a: Any, b: Any) -> bool:
|
||||
def prim_neq(a: Any, b: Any) -> bool:
|
||||
return a != b
|
||||
|
||||
@register_primitive("eq?")
|
||||
def prim_eq_identity(a: Any, b: Any) -> bool:
|
||||
"""Identity equality — true only if a and b are the same object."""
|
||||
return a is b
|
||||
|
||||
@register_primitive("eqv?")
|
||||
def prim_eqv(a: Any, b: Any) -> bool:
|
||||
"""Equivalent: identity for compound types, value for atoms."""
|
||||
if a is b:
|
||||
return True
|
||||
if isinstance(a, (int, float, str, bool)) and isinstance(b, type(a)):
|
||||
return a == b
|
||||
if (a is None or a is NIL) and (b is None or b is NIL):
|
||||
return True
|
||||
return False
|
||||
|
||||
@register_primitive("equal?")
|
||||
def prim_equal(a: Any, b: Any) -> bool:
|
||||
"""Deep structural equality (same as =)."""
|
||||
return a == b
|
||||
|
||||
@register_primitive("<")
|
||||
def prim_lt(a: Any, b: Any) -> bool:
|
||||
return a < b
|
||||
|
||||
Reference in New Issue
Block a user