added repo.or.cz incantation
[rclg.git] / clsr / ch-util / src / lists.cl
blob7e9eea9582d7496c645459fc481c527145a093cc
1 ;;;
2 ;;; lists.cl -- various lisp list utilities that make my life easier
3 ;;;
4 ;;; Author: Cyrus Harmon <ch-lisp@bobobeach.com>
5 ;;;
7 (in-package :ch-util)
9 ;;; Miscellaneous list utilities
11 (defun insert-before (new old list)
12 (labels ((build-list (old c &optional newlist)
13 (if c
14 (if (eq old (car c))
15 (append (reverse (cdr c)) (cons (car c) (cons new newlist)))
16 (build-list old (cdr c) (cons (car c) newlist)))
17 (cons new newlist))))
18 (reverse (build-list old list))))
20 (defun insert-before-all (new old list)
21 (labels ((build-list (old c &optional newlist)
22 (if c
23 (if (eq old (car c))
24 (build-list old (cdr c) (cons (car c) (cons new newlist)))
25 (build-list old (cdr c) (cons (car c) newlist)))
26 newlist)))
27 (reverse (build-list old list))))
29 (defun flatten (l)
30 (mapcan #'(lambda (x)
31 (cond ((null x) nil)
32 ((atom x) (list x))
33 (t (flatten x))))
34 l))