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.6 2003/06/12 13:08:43 kevin Exp $
12 ;;;; This file is Copyright (c) 2001-2003 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)
22 (defmacro missing-argument ()
23 `(error "Missing an argument to a constructor"))
27 (defmacro aif (test then &optional else)
31 (defmacro awhen (test-form &body body)
35 (defmacro awhile (expr &body body)
36 `(do ((it ,expr ,expr))
40 (defun mappend (fn list)
41 "Append the results of calling fn on each element of list.
42 Like mapcon, but uses append instead of nconc."
43 (apply #'append (mapcar fn list)))
45 (defun random-nth (seq)
47 "Pick a random element out of a sequence."
48 (nth (random (length seq)) nth))
50 (defun concat-symbol (&rest args)
51 "Concatenate symbols or strings to form an interned symbol"
52 (intern (format nil "~{~a~}" args)))
54 (defun cross-product (fn xlist ylist)
55 "Return a list of all (fn x y) values."
56 (mappend #'(lambda (y)
57 (mapcar #'(lambda (x) (funcall fn x y))
62 (defmacro until (test &body body)
67 (defmacro while (test &body body)
73 (defun list-to-delimited-string (list &optional (separator #\space))
74 (excl:list-to-delimited-string list separator))
77 (defun list-to-delimited-string (list &optional (separator #\space))
78 (let ((output (when list (format nil "~A" (car list)))))
79 (dolist (obj (rest list))
80 (setq output (concatenate 'string output
81 (format nil "~A" separator)
82 (format nil "~A" obj))))