From 3fbc5bfa88db1465cab73e7163c6458a297f6b6d Mon Sep 17 00:00:00 2001 From: "Paul M. Rodriguez" Date: Thu, 19 Dec 2024 16:36:54 -0600 Subject: [PATCH] Add ensure-box --- box.lisp | 11 ++++++----- package.lisp | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/box.lisp b/box.lisp index ac5a5ccd..bb727096 100644 --- a/box.lisp +++ b/box.lisp @@ -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) @@ -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))) diff --git a/package.lisp b/package.lisp index 92f91cfd..78b849ec 100644 --- a/package.lisp +++ b/package.lisp @@ -383,6 +383,7 @@ ;; Boxes. #:box #:unbox + #:ensure-box ;; Heaps. #:make-heap #:heap-insert