Add call-fn dispatch for HO forms: handle both Lambda and native callable

HO forms (map, filter, reduce, etc.) now use call-fn which dispatches
Lambda → call-lambda, native callable → apply, else → clear EvalError.
Previously call-lambda crashed with AttributeError on native functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 22:45:01 +00:00
parent d076fc1465
commit ef04beba00
3 changed files with 48 additions and 14 deletions

View File

@@ -384,6 +384,29 @@ class TestDefhandler:
assert adef.params == ["title", "body"]
class TestHOWithNativeCallable:
def test_map_with_native_fn(self):
"""map should work with native callables (primitives), not just Lambda."""
result = ev('(map str (list 1 2 3))')
assert result == ["1", "2", "3"]
def test_filter_with_native_fn(self):
result = ev('(filter number? (list 1 "a" 2 "b" 3))')
assert result == [1, 2, 3]
def test_map_with_env_fn(self):
"""map should work with Python functions registered in env."""
env = {"double": lambda x: x * 2}
result = ev('(map double (list 1 2 3))', env)
assert result == [2, 4, 6]
def test_ho_non_callable_fails_fast(self):
"""Passing a non-callable to map should error clearly."""
import pytest
with pytest.raises(sx_ref.EvalError, match="Not callable"):
ev('(map 42 (list 1 2 3))')
class TestMacros:
def test_defmacro_and_expand(self):
env = {}