1 ;;;;***************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: reversi-base.cl
6 ;;;; Purpose: Basic functions for reversi
7 ;;;; Programer: Kevin M. Rosenberg, M.D.
8 ;;;; Date Started: 1 Nov 2001
9 ;;;; CVS Id: $Id: utils.lisp,v 1.1 2002/10/25 08:36:42 kevin Exp $
11 ;;;;***************************************************************************
14 (declaim (optimize (safety 1) (debug 3) (speed 3)))
19 (defmacro aif (test then &optional else)
23 (defmacro awhen (test-form &body body)
27 (defmacro awhile (expr &body body)
28 `(do ((it ,expr ,expr))
32 (defmacro aand (&rest args)
34 ((null (cdr args)) (car args))
35 (t `(aif ,(car args) (aand ,@(cdr args))))))
37 (defmacro acond (&rest clauses)
40 (let ((cl1 (car clauses))
42 `(let ((,sym ,(car cl1)))
44 (let ((it ,sym)) ,@(cdr cl1))
45 (acond ,@(cdr clauses)))))))
47 (defmacro alambda (parms &body body)
48 `(labels ((self ,parms ,@body))
52 (defun mappend (fn list)
53 "Append the results of calling fn on each element of list.
54 Like mapcon, but uses append instead of nconc."
55 (apply #'append (mapcar fn list)))
57 (defun random-elt (seq)
58 "Pick a random element out of a sequence."
59 (elt seq (random (length seq))))
61 (defun concat-symbol (&rest args)
62 "Concatenate symbols or strings to form an interned symbol"
63 (intern (format nil "~{~a~}" args)))
65 (defun cross-product (fn xlist ylist)
66 "Return a list of all (fn x y) values."
67 (mappend #'(lambda (y)
68 (mapcar #'(lambda (x) (funcall fn x y))
73 (defmacro until (test &body body)
78 (defmacro while (test &body body)
84 (defmacro while (test &body body)
90 (defun list-to-delimited-string (list &optional (separator #\space))
91 (excl:list-to-delimited-string list separator))
94 (defun list-to-delimited-string (list &optional (separator #\space))
95 (let ((output (when list (format nil "~A" (car list)))))
96 (dolist (obj (rest list))
97 (setq output (concatenate 'string output
98 (format nil "~A" separator)
99 (format nil "~A" obj))))