pip install -e ".[dev]"python3 -m pytest tests/- Never use embedded imports (imports inside functions, methods, or conditional blocks) except for traceback.
- Don't reference torch outside of
klongpy/backends/torch_backend.py.
klongpy/interpreter.py:KlongInterpreter+KlongContext; main parse/eval loop (prog->call->eval->_eval_fn).klongpy/types.py: core AST/runtime types (KGSym,KGFn,KGCall,KGOp,KGAdverb, etc.) + type helpers.klongpy/parser.py: lexer + parser;kg_read_arrayconverts lists to backend arrays.klongpy/monads.py,klongpy/dyads.py,klongpy/adverbs.py: Klong verb/adverb semantics; most array ops delegate to backend.klongpy/backends/: backend registry + providers (NumPy default, PyTorch optional).klongpy/autograd.py: numeric gradients + torch autograd helpers.klongpy/sys_fn*.py,klongpy/sys_var.py: system functions/vars and IO helpers.klongpy/repl.py,klongpy/cli.py: REPL + CLI entrypoint (kgpy).klongpy/db,klongpy/web,klongpy/ws: optional extras (DuckDB, HTTP server, WebSockets).klongpy/lib/*.kg: standard library modules loaded via.l/.module.tests/: unit + perf tests.
klongpy/backends/base.pydefinesBackendProvider(dtype support, conversion, array ops).klongpy/backends/__init__.pyregisters backends and exposesget_backend().NumpyBackendProvideris the default; supports object dtype + strings.TorchBackendProvideris optional; usesTorchBackendto supply a numpy-like API, no object dtype/strings, supports autograd + device selection.KlongInterpreterowns a backend instance (self._backend) and exposesself.npas the backend’s numpy-like module.- Parser + writer + ops are backend-aware:
parser.kg_read_array()converts list literals usingbackend.kg_asarray.monads/dyads/adverbscall backend methods for math/array behavior.writer.kg_write()uses backend for display conversion.
klongpy/backend.pyis legacy compatibility: module-levelnpalways maps to the default numpy backend; new code should use per-interpreterbackend.
- REPL (
klongpy/repl.py) sets.systemin the interpreter with asyncio loops; IPC/web/ws modules expect this. - IPC (
klongpy/sys_fn_ipc.py): asyncio TCP + pickle; remote calls marshalKGFn/KGLambda. - Web server (
klongpy/web/sys_fn_web.py): aiohttp handlers that wrap Klong functions. - WebSockets (
klongpy/ws/sys_fn_ws.py): websockets client/server helpers; dispatches into the Klong loop. - DB (
klongpy/db/sys_fn_db.py+sys_fn_kvs.py): DuckDB + pandas tables;TableandDatabasetypes.
- Logging formatting bug in
klongpy/web/sys_fn_web.py(useslogging.info("msg", value)with no format placeholder). - IPC/WS modules still use sentinel
np.inffor “undefined” (see TODOs insys_fn_ipc.py/sys_fn_ws.py). - Web/WS/IPC expect
.systemloop handles; usingKlongInterpreter()directly without REPL setup will raise lookup errors unless.systemis set manually.