09232fd60df5
Add slot-value-or
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Sun, 03 Dec 2023 17:34:41 -0500 |
parents | f6d74c247168 |
children | edf43f3bf670 |
branches/tags | (none) |
files | DOCUMENTATION.markdown src/clos.lisp src/package.lisp |
Changes
--- 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."