Fix cond ambiguity: check ALL clauses with cond-scheme?, not just first

The cond special form misclassified Clojure-style as scheme-style when
the first test was a 2-element list like (nil? x) — treating it as a
scheme clause ((test body)) instead of a function call. Define
cond-scheme? using every? to check ALL clauses, fix eval.sx sf-cond and
render.sx eval-cond, rewrite engine.sx parse-time/filter-params as
nested if to avoid the ambiguity, add regression tests across eval/
render/aser specs. 378/378 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 16:51:41 +00:00
parent ff6c1fab71
commit cd7653d8c3
9 changed files with 76 additions and 6098 deletions

View File

@@ -1357,9 +1357,13 @@ def sf_when(args, env):
else:
return NIL
# cond-scheme?
def cond_scheme_p(clauses):
return every_p(lambda c: ((type_of(c) == 'list') if not sx_truthy((type_of(c) == 'list')) else (len(c) == 2)), clauses)
# sf-cond
def sf_cond(args, env):
if sx_truthy(((type_of(first(args)) == 'list') if not sx_truthy((type_of(first(args)) == 'list')) else (len(first(args)) == 2))):
if sx_truthy(cond_scheme_p(args)):
return sf_cond_scheme(args, env)
else:
return sf_cond_clojure(args, env)
@@ -1859,7 +1863,7 @@ def render_attrs(attrs):
# eval-cond
def eval_cond(clauses, env):
if sx_truthy(((not sx_truthy(empty_p(clauses))) if not sx_truthy((not sx_truthy(empty_p(clauses)))) else ((type_of(first(clauses)) == 'list') if not sx_truthy((type_of(first(clauses)) == 'list')) else (len(first(clauses)) == 2)))):
if sx_truthy(cond_scheme_p(clauses)):
return eval_cond_scheme(clauses, env)
else:
return eval_cond_clojure(clauses, env)
@@ -3833,4 +3837,4 @@ def render(expr, env=None):
def make_env(**kwargs):
"""Create an environment with initial bindings."""
return _Env(dict(kwargs))
return _Env(dict(kwargs))