Add two utility functions to safely get a list or a single element out of a variable.
This commit is contained in:
parent
4e544af6fc
commit
d5d0aefbbd
1 changed files with 10 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue