diff --git a/src/utils.lisp b/src/utils.lisp index b099352..9658bbd 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -7,9 +7,8 @@ (defpackage stoe.utils (:use :cl) (:nicknames :utils) - (:export :it - :aif - :awhen + (:export :it :aif :awhen + :safe-first :safe-list :group :once-only :restartable :add-hook :remove-hook :run-hook @@ -33,6 +32,14 @@ (when it ,@body))) +(defun safe-first (x) + "Return the first element of `x' if it is a list, return `x' otherwise." + (if (listp x) (first x) x)) + +(defun safe-list (x) + "Return `x' if it is a list, return '(x) otherwise." + (if (listp x) x (list x))) + (defun group (source n) "Regroup the list `source' elements by n." (when (zerop n)