|
2 | 2 |
|
3 | 3 | (in-package #:airship-scheme)
|
4 | 4 |
|
5 |
| -;;;; Define type definitions |
| 5 | +;;;; Helper functions useful for SATISFIES types or standalone tests |
| 6 | + |
| 7 | +(define-function (mathematical-integer-p :inline t) ((number number)) |
| 8 | + (zerop (nth-value 1 (round number)))) |
| 9 | + |
| 10 | +(define-function (nanp :inline t) ((number number)) |
| 11 | + "Tests if a number is NaN" |
| 12 | + (and (floatp number) (f:float-nan-p number))) |
| 13 | + |
| 14 | +(define-function (infinitep :inline t) ((number number)) |
| 15 | + "Tests if a number is an infinity" |
| 16 | + (and (floatp number) (f:float-infinity-p number))) |
| 17 | + |
| 18 | +(define-function (finitep :inline t) ((number number)) |
| 19 | + "Tests if a number is both not NaN and not an infinity" |
| 20 | + (not (and (floatp number) (or (infinitep number) (nanp number))))) |
| 21 | + |
| 22 | +;;;; Type definitions |
6 | 23 |
|
7 | 24 | ;;;; TODO: The define-scheme-predicate could go here, too
|
8 | 25 | (defmacro %define-scheme-type ((name &rest lambda-list) predicate &body body)
|
|
40 | 57 | (define-scheme-type (rational?)
|
41 | 58 | '(or rational float))
|
42 | 59 |
|
43 |
| -;;; TODO: integer? |
| 60 | +(define-scheme-type (integer?) |
| 61 | + " |
| 62 | +A Scheme integer? is a mathematical integer, which means that it is |
| 63 | +either a CL integer or it is a number (probably a float) that |
| 64 | +satisfies the mathematical definition of an integer. Since this is a |
| 65 | +SATISFIES type, it should be used sparingly. |
| 66 | +" |
| 67 | + `(or integer |
| 68 | + (and number (satisfies mathematical-integer-p)))) |
44 | 69 |
|
45 | 70 | (define-scheme-type (exact?)
|
46 | 71 | "An exact number might be real or complex, but is not a float."
|
|
56 | 81 | (define-scheme-type (exact-integer?)
|
57 | 82 | `integer)
|
58 | 83 |
|
| 84 | +(define-scheme-type* (finite?) finitep |
| 85 | + `(satisfies finitep)) |
| 86 | + |
| 87 | +(define-scheme-type* (infinite?) infinitep |
| 88 | + `(satisfies infinitep)) |
| 89 | + |
| 90 | +(define-scheme-type* (nan?) nanp |
| 91 | + `(satisfies nanp)) |
| 92 | + |
59 | 93 | (define-scheme-type* (zero?) zerop
|
60 |
| - '(or (real 0 0) (complex (real 0 0)))) |
| 94 | + `(or (real 0 0) |
| 95 | + (complex (real 0 0)))) |
61 | 96 |
|
62 | 97 | (define-scheme-type (boolean?)
|
63 | 98 | "
|
|
0 commit comments