new file, factored out type checking functions. Better data structure hiding is...
[CommonLispStat.git] / lstypes.lsp
blobcaf8b033cf919a0098b6a471768a1e532a1cf273
1 ;;; -*- mode: lisp -*-
2 ;;; Copyright (c) 2005--2007, by A.J. Rossini <blindglobe@gmail.com>
3 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
4 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
6 (defpackage :lisp-stat-types
7 (:use :common-lisp)
8 (:export fixnump check-nonneg-fixnum check-one-fixnum
9 check-one-real check-one-number check-sequence))
11 (in-package :lisp-stat-types)
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ;;;;
16 ;;;; Type Checking Functions
17 ;;;;
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 ;;; Moved out of lsbasics.lsp
22 (defun fixnump (x)
23 "Args: (x)
24 Returns T if X is a fixnum; NIL otherwise."
25 (declare (inline typep))
26 (typep x 'fixnum))
28 (defun check-nonneg-fixnum (x)
29 (if (and (fixnump x) (<= 0 x)) x (error "not a non-negative fixnum")))
31 (defun check-one-fixnum (x)
32 (if (not (fixnump x)) (error "not a fixnum - ~a" x)))
34 (defun check-one-real (a)
35 (if (not (or (rationalp a) (floatp a)))
36 (error "not a real number ~s" a)
37 t))
39 (defun check-one-number (a)
40 (if (not (numberp a))
41 (error "not a number ~s" a)
42 t))
44 (defun check-sequence (a)
45 (if (not (or (vectorp a) (consp a))) (error "not a sequence - ~s" a)))