Remove a bogus declare ignore
[cxml.git] / xml / util.lisp
blobc48a17717f55153ea5e49839d9383878520f1b72
1 ;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: RUNES; -*-
2 ;;; ---------------------------------------------------------------------------
3 ;;; Title: Some common utilities for the Closure browser
4 ;;; Created: 1997-12-27
5 ;;; Author: Gilbert Baumann <unk6@rz.uni-karlsruhe.de>
6 ;;; License: Lisp-LGPL (See file COPYING for details).
7 ;;; ---------------------------------------------------------------------------
8 ;;; (c) copyright 1997-1999 by Gilbert Baumann
10 ;;; This code is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the version 2.1 of the GNU Lesser General Public
12 ;;; License as published by the Free Software Foundation, as clarified
13 ;;; by the "Preamble to the Gnu Lesser General Public License" found in
14 ;;; the file COPYING.
15 ;;;
16 ;;; This code is distributed in the hope that it will be useful,
17 ;;; but without any warranty; without even the implied warranty of
18 ;;; merchantability or fitness for a particular purpose. See the GNU
19 ;;; Lesser General Public License for more details.
20 ;;;
21 ;;; Version 2.1 of the GNU Lesser General Public License is in the file
22 ;;; COPYING that was distributed with this file. If it is not present,
23 ;;; you can access it from http://www.gnu.org/copyleft/lesser.txt (until
24 ;;; superseded by a newer version) or write to the Free Software
25 ;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 ;; Changes
29 ;; When Who What
30 ;; ----------------------------------------------------------------------------
31 ;; 1999-08-24 GB = fixed MULTIPLE-VALUE-OR it now takes any number of
32 ;; subforms
35 (in-package :cxml)
37 ;;; --------------------------------------------------------------------------------
38 ;;; Meta functions
40 (defun curry (fun &rest args)
41 #'(lambda (&rest more)
42 (apply fun (append args more))))
44 (defun rcurry (fun &rest args)
45 #'(lambda (&rest more)
46 (apply fun (append more args))))
48 (defun compose (f g)
49 #'(lambda (&rest args)
50 (funcall f (apply g args))))
52 ;;; --------------------------------------------------------------------------------
53 ;;; while and until
55 (defmacro while (test &body body)
56 `(until (not ,test) ,@body))
58 (defmacro until (test &body body)
59 `(do () (,test) ,@body))
61 ;; prime numbers
63 (defun primep (n)
64 "Returns true, iff `n' is prime."
65 (and (> n 2)
66 (do ((i 2 (+ i 1)))
67 ((> (* i i) n) t)
68 (cond ((zerop (mod n i)) (return nil))))))
70 (defun nearest-greater-prime (n)
71 "Returns the smallest prime number no less than `n'."
72 (cond ((primep n) n)
73 ((nearest-greater-prime (+ n 1)))))