Add ALPHA-CHAR-P. FIND and FIND-If work also on sequences
authorDavid Vázquez <davazp@gmail.com>
Sat, 4 May 2013 16:06:41 +0000 (17:06 +0100)
committerDavid Vázquez <davazp@gmail.com>
Sat, 4 May 2013 16:06:41 +0000 (17:06 +0100)
src/boot.lisp

index 14d0ab9..ab043a9 100644 (file)
 (defun atom (x)
   (not (consp x)))
 
-(defun find (item list &key (key #'identity) (test #'eql))
-  (dolist (x list)
-    (when (funcall test (funcall key x) item)
-      (return x))))
-
 (defun remove (x list)
   (cond
     ((null list)
     (t
      (remove-if-not func (cdr list)))))
 
+(defun alpha-char-p (x)
+  (or (<= (char-code #\a) (char-code x) (char-code #\z))
+      (<= (char-code #\Z) (char-code x) (char-code #\Z))))
+
 (defun digit-char-p (x)
   (if (and (<= (char-code #\0) (char-code x) (char-code #\9)))
       (- (char-code x) (char-code #\0))
          (t
           (error "type-error!"))))))
 
+(defun find (item sequence &key (key #'identity) (test #'eql))
+  (do-sequence (x sequence)
+    (when (funcall test (funcall key x) item)
+      (return x))))
+
+(defun find-if (predicate sequence &key (key #'identity))
+  (do-sequence (x sequence)
+    (when (funcall predicate (funcall key x))
+      (return x))))
+
 (defun some (function seq)
   (do-sequence (elt seq)
     (when (funcall function elt)