/[the-feebs-war]/utils.lisp
ViewVC logotype

Contents of /utils.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations)
Sun Feb 17 20:29:26 2008 UTC (6 years, 2 months ago) by gmilare
File size: 1488 byte(s)
1 ;;; -*- Common Lisp -*-
2
3 #| Copyright (c) 2007,2008 Gustavo Henrique Milar´┐Ż
4
5 This file is part of The Feebs War.
6
7 The Feebs War is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 The Feebs War is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with The Feebs War. If not, see <http://www.gnu.org/licenses/>.
19 |#
20
21
22 (in-package :the-feebs-war)
23
24
25
26 (defun bound-random (start min avg max)
27 (+ start
28 (* (expt -1 (random 2))
29 (let ((sort (random 2.0)))
30 (round
31 (if (< sort 1.0)
32 (+ min (* sort (- avg min)))
33 (+ avg (* (1- sort) (- max avg)))))))))
34
35 (defun random-elt (seq)
36 (if seq
37 (elt seq (random (length seq)))))
38
39 (defmacro ensure-bound (elt min max)
40 `(setf ,elt (bound ,elt ,min ,max)))
41
42 (defun bound (elt min max)
43 (max min (min max elt)))
44
45 (defmacro aif (test then &optional else)
46 `(let ((it ,test))
47 (if it ,then ,else)))
48
49 (defmacro awhen (test &rest body)
50 `(let ((it ,test))
51 (when it ,@body)))
52
53 (defun rcurry (func &rest args)
54 #'(lambda (x)
55 (apply func x args)))

  ViewVC Help
Powered by ViewVC 1.1.5