From b3b8f3694c6f4a0506ef3c2054fef4691b5c34eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Sat, 4 May 2013 17:06:41 +0100 Subject: [PATCH] Add ALPHA-CHAR-P. FIND and FIND-If work also on sequences --- src/boot.lisp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/boot.lisp b/src/boot.lisp index 14d0ab9..ab043a9 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -374,11 +374,6 @@ (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) @@ -407,6 +402,10 @@ (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)) @@ -440,6 +439,16 @@ (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) -- 1.7.10.4