scheme: Phase 7 — eval/interaction-environment/null-env + 13 tests [shapes-reflective]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s

runtime.sx binds R7RS reflective primitives:
- eval EXPR ENV
- interaction-environment        — returns env captured by closure
- null-environment VERSION       — fresh empty env (ignores version)
- scheme-report-environment N    — fresh full standard env
- environment? V

interaction-environment closes over the standard env being built;
each invocation of scheme-standard-env produces a distinct
interaction env that returns ITSELF when queried — so user-side
(define name expr) inside (eval ... (interaction-environment))
persists for subsequent (eval 'name ...) lookups.

13 tests cover:
- eval over quoted forms (literal + constructed via list)
- define-then-lookup through interaction-environment
- eqv? identity of interaction-environment across calls
- sandbox semantics: eval in null-environment errors on +
- scheme-report-environment is fresh and distinct from interaction

**Second consumer for lib/guest/reflective/evaluator.sx unlocked.**
Scheme's eval/interaction-environment/null-environment triple is
the same protocol Kernel exposes via eval-applicative /
get-current-environment / make-environment. Extraction now
satisfies the two-consumer rule — same playbook as env.sx and
class-chain.sx, awaits a follow-up commit to actually extract
the kit.

270 total Scheme tests (62 + 23 + 49 + 78 + 25 + 20 + 13).
This commit is contained in:
2026-05-14 06:45:39 +00:00
parent 9a7ca54902
commit 342e1a2ccf
2 changed files with 134 additions and 0 deletions

View File

@@ -586,6 +586,40 @@
((and (dict? outcome) (get outcome :scm-weh-raised))
(scheme-apply handler (list (get outcome :value))))
(:else outcome))))))))
;; ── R7RS reflection: eval / environment accessors ───────
;; eval EXPR ENV — apply the evaluator to a user-supplied AST.
(scheme-env-bind! env "eval"
(fn (args)
(cond
((not (= (length args) 2))
(error "eval: expects (eval expr env)"))
(:else (scheme-eval (first args) (nth args 1))))))
;; interaction-environment — the env we're currently building.
;; The closure captures `env`, so each invocation of
;; scheme-standard-env produces a distinct interaction env
;; whose interaction-environment fn returns itself.
(scheme-env-bind! env "interaction-environment"
(fn (args)
(cond
((not (= (length args) 0))
(error "interaction-environment: expects 0 args"))
(:else env))))
;; null-environment — fresh empty env. R7RS ignores version arg.
(scheme-env-bind! env "null-environment"
(fn (args)
(cond
((not (= (length args) 1))
(error "null-environment: expects (version)"))
(:else (scheme-make-env)))))
;; scheme-report-environment — fresh full standard env.
(scheme-env-bind! env "scheme-report-environment"
(fn (args)
(cond
((not (= (length args) 1))
(error "scheme-report-environment: expects (version)"))
(:else (scheme-standard-env)))))
(scheme-env-bind! env "environment?"
(scm-unary "environment?" (fn (v) (scheme-env? v))))
;; dynamic-wind BEFORE THUNK AFTER — runs BEFORE, then THUNK,
;; then AFTER. If THUNK raises, AFTER still runs before the
;; raise propagates. This is the basic-correctness version;