generalized nop to handle more args.
[CommonLispStat.git] / lstypes.lsp
blob4c90c642f9498115778980e782e1eea6e2468d2e
1 ;;; -*- mode: lisp -*-
3 ;;; Copyright (c) 2005--2007, by A.J. Rossini <blindglobe@gmail.com>
4 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
5 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
7 (in-package :cl-user)
9 (defpackage :lisp-stat-types
10 (:use :common-lisp)
11 (:export fixnump check-nonneg-fixnum check-one-fixnum
12 check-one-real check-one-number))
14 (in-package :lisp-stat-types)
16 ;;; Type Checking Functions
17 ;;; (Moved out of lsbasics.lsp, placed there by initial design).
19 (defun fixnump (x)
20 "Args: (x)
21 Returns T if X is a fixnum; NIL otherwise."
22 (declare (inline typep))
23 (typep x 'fixnum))
25 (defun check-nonneg-fixnum (x)
26 "Ensure that x or all elts of x are non-negative fixnums."
27 (cond ((listp x)
28 (map 'list #'check-one-nonneg-fixnum x))
29 (t (check-one-nonneg-fixnum x))))
31 (defun check-one-nonneg-fixnum (x)
32 "return value if true, throw error otherwise."
33 (if (and (fixnump x) (<= 0 x))
35 (error "Expected non-negative fixnum, but got ~A" x)))
37 (defun check-one-fixnum (x)
38 (if (not (fixnump x))
39 (error "not a fixnum - ~a" x)))
41 (defun check-one-real (a)
42 (if (not (or (rationalp a) (floatp a)))
43 (error "not a real number ~s" a)
44 t))
46 (defun check-one-number (a)
47 (if (not (numberp a))
48 (error "not a number ~s" a)
49 t))