cl: Phase 4 CLOS complete — generic functions, multi-dispatch, method qualifiers, 437/437 tests

- lib/common-lisp/clos.sx (27 forms): class registry (8 built-in classes),
  defclass/make-instance/slot-value/slot-boundp/change-class, defgeneric/defmethod
  with :before/:after/:around, clos-call-generic (standard combination: sort by
  specificity, fire befores, call primary chain, fire afters reversed),
  call-next-method/next-method-p, with-slots, deferred accessor installation
- lib/common-lisp/tests/clos.sx: 41 tests (class-of, subclass-of?, defclass,
  make-instance, slot ops, inheritance, method specificity, qualifiers, accessors,
  with-slots, change-class)
- lib/common-lisp/tests/programs/geometry.sx: 12 tests — intersect generic
  dispatching on geo-point×geo-point, geo-point×geo-line, geo-line×geo-line,
  geo-line×geo-plane (multi-dispatch by class precedence)
- lib/common-lisp/tests/programs/mop-trace.sx: 13 tests — :before/:after
  tracing on area and describe-shape generics, call-next-method in circle/rect
- eval.sx: dynamic variables — cl-apply-dyn saves/restores global slot for
  specials; cl-mark-special!/cl-special?/cl-dyn-unbound; defvar now marks
  specials; let/let* rebind via cl-apply-dyn; 8 new tests (182 eval total)
- conformance.sh + test.sh: Phase 4 suites wired in
- plans/common-lisp-on-sx.md: Phase 4 + dynamic variable boxes ticked

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 11:38:37 +00:00
parent 71c4b5e33f
commit 0e426cfea8
11 changed files with 1529 additions and 36 deletions

View File

@@ -436,3 +436,31 @@
(cl-test "values: truthy primary in if"
(ev "(if (values 42 nil) 'yes 'no)")
"YES")
;; --- Dynamic variables ---
(cl-test "defvar marks special"
(do (ev "(defvar *dv* 10)")
(cl-special? "*DV*"))
true)
(cl-test "defvar: let rebinds dynamically"
(ev "(progn (defvar *x* 1) (defun get-x () *x*) (let ((*x* 99)) (get-x)))")
99)
(cl-test "defvar: binding restores after let"
(ev "(progn (defvar *yrst* 5) (let ((*yrst* 42)) *yrst*) *yrst*)")
5)
(cl-test "defparameter marks special"
(do (ev "(defparameter *dp* 0)")
(cl-special? "*DP*"))
true)
(cl-test "defparameter: let rebinds dynamically"
(ev "(progn (defparameter *z* 10) (defun get-z () *z*) (let ((*z* 77)) (get-z)))")
77)
(cl-test "defparameter: always assigns"
(ev "(progn (defparameter *p* 1) (defparameter *p* 2) *p*)")
2)
(cl-test "dynamic binding: nested lets"
(ev "(progn (defvar *n* 0) (let ((*n* 1)) (let ((*n* 2)) *n*)))")
2)
(cl-test "dynamic binding: restores across nesting"
(ev "(progn (defvar *m* 10) (let ((*m* 20)) (let ((*m* 30)) nil)) *m*)")
10)