Commit afaf1a16 authored by Jan Moringen's avatar Jan Moringen
Browse files

use implementation's EMPTYP when available

Using the implementation's EMPTYP has the potential advantage of
supporting user-defined sequence types (as is the case with SBCL).

This commit tests for SEQUENCE:EMPTYP and defines ALEXANDRIA:EMPTYP in
terms of it.

For implementations that do not provide SEQUENCE:EMPTYP, nothing
changes.
parent 8b89a71b
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -155,6 +155,12 @@ that are not lists."
  `(or proper-list
       (and (not list) sequence)))

(eval-when (:compile-toplevel :load-toplevel :execute)
  (when (and (find-package '#:sequence)
             (find-symbol (string '#:emptyp) '#:sequence))
    (pushnew 'sequence-emptyp *features*)))

#-alexandria::sequence-emptyp
(defun emptyp (sequence)
  "Returns true if SEQUENCE is an empty sequence. Signals an error if SEQUENCE
is not a sequence."
@@ -162,6 +168,14 @@ is not a sequence."
    (list (null sequence))
    (sequence (zerop (length sequence)))))

#+alexandria::sequence-emptyp
(declaim (ftype (function (sequence) (values boolean &optional)) emptyp))
#+alexandria::sequence-emptyp
(setf (symbol-function 'emptyp) (symbol-function 'sequence:emptyp))
#+alexandria::sequence-emptyp
(define-compiler-macro emptyp (sequence)
  `(sequence:emptyp ,sequence))

(defun length= (&rest sequences)
  "Takes any number of sequences or integers in any order. Returns true iff
the length of all the sequences and the integers are equal. Hint: there's a