Visual guarding and predicate cleanup

This commit is contained in:
BirDt_ 2026-04-06 13:42:31 +08:00
parent 71e92641f7
commit 5a67f5c53f
2 changed files with 55 additions and 10 deletions

View file

@ -1,7 +1,8 @@
(module (engine guards) ()
(import scheme
(chicken base)
(chicken module))
(chicken module)
(srfi 99))
;; Utility function for guarding parameter values
(export guarded-parameter)
@ -10,4 +11,15 @@
(if (predicate val)
val
default))))
;; Shorthand for defining a guarded mutator for a record field
(define (guarded-mutator record-type field predicate)
(lambda (rec val)
(assert (record-type rec))
(assert (predicate val))
((rtd-mutator (record-rtd rec) field) rec val)))
;; TODO: define a similar function here for record constructor
;; TODO: define a similar function here for binary operations on records
)