From: David Vázquez Date: Mon, 6 May 2013 13:27:44 +0000 (+0100) Subject: Organize the functions in the file X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=d204a3907769bfafd55fe8ca1b927a0b61812a56;p=jscl.git Organize the functions in the file --- diff --git a/src/sequence.lisp b/src/sequence.lisp index 7c823dc..93e3fdd 100644 --- a/src/sequence.lisp +++ b/src/sequence.lisp @@ -39,30 +39,19 @@ (when (funcall test 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) - (return-from some t)))) - -(defun every (function seq) - (do-sequence (elt seq) - (unless (funcall function elt) - (return-from every nil))) - t) - -(defun position (elt sequence) - (let ((pos 0)) - (do-sequence (x seq) - (when (eq elt x) - (return)) - (incf pos)) - pos)) +(defun find-if (predicate sequence &key key) + (if key + (do-sequence (x sequence) + (when (funcall predicate (funcall key x)) + (return x))) + (do-sequence (x sequence) + (when (funcall predicate x) + (return x))))) +(defun position (elt sequence &key (test #'eql)) + (do-sequence (x seq index) + (when (funcall test elt x) + (return index)))) (defun remove (x seq) (cond @@ -92,7 +81,19 @@ (or vector seq))))) -;;; TODO: Support vectors +(defun some (function seq) + (do-sequence (elt seq) + (when (funcall function elt) + (return-from some t)))) + +(defun every (function seq) + (do-sequence (elt seq) + (unless (funcall function elt) + (return-from every nil))) + t) + + +;;; TODO: Support both List and vectors in the following functions (defun remove-if (func list) (cond