we aren't using matlisp yet, I've not made the hacked version with its new deps available
[CommonLispStat.git] / lstypes.lsp
blobd91e5373e2c13ea15175c4790026aa255d00797b
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)
10 (defpackage :lisp-stat-types
11 (:documentation "Provides some typeing for LispStat, but is clearly
12 a bit incomplete.")
13 (:use :common-lisp)
14 (:export fixnump
15 check-nonneg-fixnum check-one-nonneg-fixnum
16 check-one-fixnum check-one-real check-one-number))
18 (in-package :lisp-stat-types)
20 ;;; Type Checking Functions
21 ;;; (Moved out of lsbasics.lsp, placed there by initial design).
23 (defun fixnump (x)
24 "Args: (x)
26 Returns T if X is a fixnum; NIL otherwise."
27 (declare (inline typep))
28 (typep x 'fixnum))
30 (defun check-nonneg-fixnum (x)
31 "Ensure that x or all elts of x are non-negative fixnums."
32 (cond ((typep x 'sequence) ;; seq rather than list, allows for vector?
33 (map 'list #'check-one-nonneg-fixnum x))
34 (t (check-one-nonneg-fixnum x))))
36 (defun check-one-nonneg-fixnum (x)
37 "return value if true, throw error otherwise."
38 (if (and (fixnump x) (<= 0 x))
40 (error "Expected non-negative fixnum, but got ~A" x)))
42 (defun check-one-fixnum (x)
43 (if (not (fixnump x))
44 (error "not a fixnum - ~a" x)))
46 (defun check-one-real (a)
47 (if (not (or (rationalp a) (floatp a)))
48 (error "not a real number ~s" a)
49 t))
51 (defun check-one-number (a)
52 (if (not (numberp a))
53 (error "not a number ~s" a)
54 t))