giles
653be79c8d
Step 7c complete: protocols (define-protocol, implement, satisfies?)
Trait-like dispatch system for record types:
(define-record-type <point>
(make-point x y) point? (x point-x) (y point-y))
(define-protocol Displayable (show self))
(implement Displayable <point>
(show self (str (point-x self) "," (point-y self))))
(show (make-point 3 4)) ;; => "3,4"
(satisfies? "Displayable" (make-point 1 2)) ;; => true
(satisfies? "Displayable" 42) ;; => false
Implementation:
- *protocol-registry* global dict stores protocol specs + implementations
- define-protocol creates dispatch functions via eval-expr (dynamic lambdas)
- implement registers method lambdas keyed by record type name
- Dispatch: (type-of self) → lookup in protocol impls → call method
- satisfies? checks if a record type has implementations for a protocol
2645 tests pass (+1 from protocol self-test).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:29:35 +00:00
..
2026-03-26 00:54:23 +00:00
2026-04-03 21:26:20 +00:00
2026-04-03 18:07:35 +00:00
2026-04-03 18:19:19 +00:00
2026-04-04 00:08:00 +00:00
2026-04-04 15:29:35 +00:00
2026-04-03 20:16:26 +00:00
2026-04-04 12:39:20 +00:00
2026-04-04 12:39:20 +00:00
2026-04-04 13:34:11 +00:00
2026-04-03 18:55:43 +00:00