Initial commit - fix problems & refactor code

This commit is contained in:
2025-12-22 19:10:46 +03:00
commit ff36917cb5
39 changed files with 1499 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
from typing import Any
from core.primitives.symbol import symbolKey, isSymbol
from core.primitives.list import NIL, isList, cons, car, cdr
def macroExpand(body: Any, bindings: dict[str, Any]) -> Any:
"""Expand a macro by substituting bindings into the body.
Args:
body: The macro body to expand.
bindings: Dictionary of symbol-to-value bindings.
Returns:
The expanded body.
"""
if isSymbol(body):
if symbolKey(body) in bindings:
return bindings[symbolKey(body)] # auto quote
return body
if isList(body):
if body == NIL:
return NIL
return cons(
macroExpand(car(body), bindings), macroExpand(cdr(body), bindings)
)
return body