1 ;;;;***************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: reversi-base.lisp
6 ;;;; Purpose: Basic functions for reversi
7 ;;;; Programer: Kevin M. Rosenberg
8 ;;;; Date Started: 1 Nov 2001
10 ;;;; $Id: utils.lisp,v 1.4 2003/05/06 15:51:20 kevin Exp $
12 ;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg
14 ;;;; Reversi users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;;***************************************************************************
19 (in-package #:reversi)
21 (eval-when (:compile-toplevel)
22 (declaim (optimize (safety 1) (space 0) (speed 3) (compilation-speed 0))))
24 (defmacro missing-argument ()
25 `(error "Missing an argument to a constructor"))
29 (defmacro aif (test then &optional else)
33 (defmacro awhen (test-form &body body)
37 (defmacro awhile (expr &body body)
38 `(do ((it ,expr ,expr))
42 (defun mappend (fn list)
43 "Append the results of calling fn on each element of list.
44 Like mapcon, but uses append instead of nconc."
45 (apply #'append (mapcar fn list)))
47 (defun random-elt (seq)
48 "Pick a random element out of a sequence."
49 (elt seq (random (length seq))))
51 (defun concat-symbol (&rest args)
52 "Concatenate symbols or strings to form an interned symbol"
53 (intern (format nil "~{~a~}" args)))
55 (defun cross-product (fn xlist ylist)
56 "Return a list of all (fn x y) values."
57 (mappend #'(lambda (y)
58 (mapcar #'(lambda (x) (funcall fn x y))
63 (defmacro until (test &body body)
68 (defmacro while (test &body body)
74 (defun list-to-delimited-string (list &optional (separator #\space))
75 (excl:list-to-delimited-string list separator))
78 (defun list-to-delimited-string (list &optional (separator #\space))
79 (let ((output (when list (format nil "~A" (car list)))))
80 (dolist (obj (rest list))
81 (setq output (concatenate 'string output
82 (format nil "~A" separator)
83 (format nil "~A" obj))))