;;;;*************************************************************************** ;;;; ;;;; FILE IDENTIFICATION ;;;; ;;;; Name: reversi-base.cl ;;;; Purpose: Basic functions for reversi ;;;; Programer: Kevin M. Rosenberg, M.D. ;;;; Date Started: 1 Nov 2001 ;;;; CVS Id: $Id: utils.lisp,v 1.1 2002/10/25 08:36:42 kevin Exp $ ;;;; ;;;;*************************************************************************** (in-package :reversi) (declaim (optimize (safety 1) (debug 3) (speed 3))) ;; Anaphoric macros (defmacro aif (test then &optional else) `(let ((it ,test)) (if it ,then ,else))) (defmacro awhen (test-form &body body) `(aif ,test-form (progn ,@body))) (defmacro awhile (expr &body body) `(do ((it ,expr ,expr)) ((not it)) ,@body)) (defmacro aand (&rest args) (cond ((null args) t) ((null (cdr args)) (car args)) (t `(aif ,(car args) (aand ,@(cdr args)))))) (defmacro acond (&rest clauses) (if (null clauses) nil (let ((cl1 (car clauses)) (sym (gensym))) `(let ((,sym ,(car cl1))) (if ,sym (let ((it ,sym)) ,@(cdr cl1)) (acond ,@(cdr clauses))))))) (defmacro alambda (parms &body body) `(labels ((self ,parms ,@body)) #'self)) (defun mappend (fn list) "Append the results of calling fn on each element of list. Like mapcon, but uses append instead of nconc." (apply #'append (mapcar fn list))) (defun random-elt (seq) "Pick a random element out of a sequence." (elt seq (random (length seq)))) (defun concat-symbol (&rest args) "Concatenate symbols or strings to form an interned symbol" (intern (format nil "~{~a~}" args))) (defun cross-product (fn xlist ylist) "Return a list of all (fn x y) values." (mappend #'(lambda (y) (mapcar #'(lambda (x) (funcall fn x y)) xlist)) ylist)) (defmacro until (test &body body) `(do () (,test) ,@body)) (defmacro while (test &body body) `(do () ((not ,test)) ,@body)) #+ignore (defmacro while (test &body body) `(do () (not ,test) ,@body)) #+excl (defun list-to-delimited-string (list &optional (separator #\space)) (excl:list-to-delimited-string list separator)) #-excl (defun list-to-delimited-string (list &optional (separator #\space)) (let ((output (when list (format nil "~A" (car list))))) (dolist (obj (rest list)) (setq output (concatenate 'string output (format nil "~A" separator) (format nil "~A" obj)))) output))