Add two utility functions to safely get a list or a single element out of a variable.

This commit is contained in:
Renaud Casenave-Péré 2014-09-19 17:17:58 +09:00
parent 4e544af6fc
commit d5d0aefbbd

View file

@ -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)