chiark
/
gitweb
/
~mdw
/
clg
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e7a1c08
)
Added function DELETE-COLLECT-IF
author
espen
<espen>
Tue, 25 Apr 2006 20:26:04 +0000
(20:26 +0000)
committer
espen
<espen>
Tue, 25 Apr 2006 20:26:04 +0000
(20:26 +0000)
tools/utils.lisp
patch
|
blob
|
blame
|
history
diff --git
a/tools/utils.lisp
b/tools/utils.lisp
index 23671d3d17d4e6be4dafe202d956b9672e23360e..27aab4dacf248812f87d933a9606440d78218271 100644
(file)
--- a/
tools/utils.lisp
+++ b/
tools/utils.lisp
@@
-20,13
+20,14
@@
;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-;; $Id: utils.lisp,v 1.
1 2006/03/29 09:51:55
espen Exp $
+;; $Id: utils.lisp,v 1.
2 2006/04/25 20:26:04
espen Exp $
(defpackage #:clg-utils
(:use #:common-lisp)
(:export #:read-lines #:mklist #:namep #:funcallable #:return-if #:when-bind
#:visible-char-p #:whitespace-p #:split-string-if #:split-string
(defpackage #:clg-utils
(:use #:common-lisp)
(:export #:read-lines #:mklist #:namep #:funcallable #:return-if #:when-bind
#:visible-char-p #:whitespace-p #:split-string-if #:split-string
- #:concatenate-strings #:string-prefix-p #:get-all))
+ #:concatenate-strings #:string-prefix-p #:get-all
+ #:delete-collect-if))
(in-package #:clg-utils)
(in-package #:clg-utils)
@@
-74,8
+75,8
@@
(defun split-string-if (string predicate)
(subseq string 0 pos)
(split-string-if (subseq string pos) predicate)))))
(subseq string 0 pos)
(split-string-if (subseq string pos) predicate)))))
-(defun split-string (string &
optional
(delimiter #'whitespace-p)
-
&key
(start 0) (end (length string)))
+(defun split-string (string &
key
(delimiter #'whitespace-p)
+ (start 0) (end (length string)))
(let* ((predicate (if (functionp delimiter)
delimiter
#'(lambda (char)
(let* ((predicate (if (functionp delimiter)
delimiter
#'(lambda (char)
@@
-86,7
+87,7
@@
(defun split-string (string &optional (delimiter #'whitespace-p)
(cons
(subseq string from (or to end))
(when to
(cons
(subseq string from (or to end))
(when to
- (split-string string predicate :start to :end end)))))))
+ (split-string string
:delimiter
predicate :start to :end end)))))))
(defun concatenate-strings (strings &optional delimiter)
(if (not (rest strings))
(defun concatenate-strings (strings &optional delimiter)
(if (not (rest strings))
@@
-107,3
+108,16
@@
(defun get-all (plist property)
(get-properties plist (list property))
(when tail
(cons value (get-all (cddr tail) property)))))
(get-properties plist (list property))
(when tail
(cons value (get-all (cddr tail) property)))))
+
+
+(defun delete-collect-if (predicate seq)
+ (let ((head (cons nil seq)))
+ (values
+ (loop
+ for tmp on head
+ while (cdr tmp)
+ when (funcall predicate (second tmp))
+ collect (let ((elm (second tmp)))
+ (setf (cdr tmp) (cddr tmp))
+ elm))
+ (cdr head))))