--- a/DOCUMENTATION.markdown Sun Dec 03 17:29:39 2023 -0500
+++ b/DOCUMENTATION.markdown Sun Dec 03 17:34:41 2023 -0500
@@ -412,6 +412,12 @@
Return the `slot-value` of `slot` in `object`, setting it to `default` if unbound.
+### `SLOT-VALUE-OR` (function)
+
+ (SLOT-VALUE-OR OBJECT SLOT &OPTIONAL DEFAULT)
+
+Return the `slot-value` of `slot` in `object`, or `default` if unbound.
+
## Package `LOSH.CONTROL-FLOW`
Utilities for managing control flow.
--- a/src/clos.lisp Sun Dec 03 17:29:39 2023 -0500
+++ b/src/clos.lisp Sun Dec 03 17:34:41 2023 -0500
@@ -46,6 +46,12 @@
,@options)))
+(defun slot-value-or (object slot &optional default)
+ "Return the `slot-value` of `slot` in `object`, or `default` if unbound."
+ (if (slot-boundp object slot)
+ (slot-value object slot)
+ default))
+
(defmacro ensure-slot-value (object slot &optional default)
"Return the `slot-value` of `slot` in `object`, setting it to `default` if unbound."
--- a/src/package.lisp Sun Dec 03 17:29:39 2023 -0500
+++ b/src/package.lisp Sun Dec 03 17:34:41 2023 -0500
@@ -50,6 +50,7 @@
(:export
:defclass*
:define-condition*
+ :slot-value-or
:ensure-slot-value))
(defpackage :losh.eldritch-horrors