lin regr example; must debug, factor into regression.lisp
[CommonLispStat.git] / src / basics / lstypes.lsp
blob9722a2c18cda91b1e45f561cf623956391e6acd6
1 ;;; -*- mode: lisp -*-
3 ;;; Copyright (c) 2005--2008, 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 :lisp-stat-types)
9 ;;; Type Checking Functions
10 ;;; (Moved out of lsbasics.lsp, placed there by initial design).
12 (defun fixnump (x)
13 "Args: (x)
15 Returns T if X is a fixnum; NIL otherwise."
16 (declare (inline typep))
17 (typep x 'fixnum))
19 (defun check-nonneg-fixnum (x)
20 "Ensure that x or all elts of x are non-negative fixnums."
21 (cond ((typep x 'sequence) ;; seq rather than list, allows for vector?
22 (map 'list #'check-one-nonneg-fixnum x))
23 (t (check-one-nonneg-fixnum x))))
25 (defun check-one-nonneg-fixnum (x)
26 "return value if true, throw error otherwise."
27 (if (and (fixnump x) (<= 0 x))
29 (error "Expected non-negative fixnum, but got ~A" x)))
31 (defun check-one-fixnum (x)
32 (if (not (fixnump x))
33 (error "not a fixnum - ~a" x)))
35 (defun check-one-real (a)
36 (if (not (or (rationalp a) (floatp a)))
37 (error "not a real number ~s" a)
38 t))
40 (defun check-one-number (a)
41 (if (not (numberp a))
42 (error "not a number ~s" a)
43 t))