Skip to content

Commit

Permalink
Add ensure-box
Browse files Browse the repository at this point in the history
  • Loading branch information
ruricolist committed Dec 19, 2024
1 parent ebd9c5c commit 3fbc5bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions box.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ accessor `unbox'.
Serapeum attempts to provide the guarantee that, on Lisps that support
atomic operations (compare-and-swap), `unbox` on boxes should be
updateable atomically. (See
[atomics](https://github.com/Shinmera/atomics)).
At the moment, boxes are implemented as structures, but that may
change. In particular, you should not depend on being able to
recognize boxes using a type or predicate."
[atomics](https://github.com/Shinmera/atomics))."
unbox)

(declaim-freeze-type box)
Expand Down Expand Up @@ -60,3 +56,8 @@ recognize boxes using a type or predicate."
(typep ,b 'box)
(unbox ,b)
,x)))

(-> ensure-box (t) box)
(defun ensure-box (x)
"Return X if boxed, otherwise a box containing X."
(if (boxp x) x (box x)))
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
;; Boxes.
#:box
#:unbox
#:ensure-box
;; Heaps.
#:make-heap
#:heap-insert
Expand Down

0 comments on commit 3fbc5bf

Please sign in to comment.