https://github.com/m2ym/trivial-types.git
git clone 'https://github.com/m2ym/trivial-types.git'
(ql:quickload :trivial-types)
TRIVIAL-TYPES provides missing but important type definitions such as PROPER-LIST, ASSOCIATION-LIST, PROPERTY-LIST and TUPLE.
By using these types, you can keep type declarations more accurate. For example, you may write a class definition like:
(defclass person ()
((name :type string))
((age :type fixnum))
((friends :type list)))
However, it is not obvious for anyone except you that FRIENDS slot has only a list of person. If you want declare FRIENDS slot more accurately, PROPER-LIST is the best for that:
(defclass person ()
((name :type string))
((age :type fixnum))
((friends :type (proper-list person))))
In addition, TRIVIAL-TYPES also provides standard designators defined in ANSI standard such as PACKAGE-DESIGNATOR. They are useful when you write a function that takes a package-oid argument like:
(defun list-external-symbols (package)
(declare (package-designator package))
(loop for symbol being the external-symbol of package
collect symbol))
proper-list-p object
Returns true if OBJECT is a proper list.
Examples:
(proper-list-p 1) => NIL
(proper-list-p '(1 . 2)) => NIL
(proper-list-p nil) => T
(proper-list-p '(1 2 3)) => T
proper-list &optional (element-type '*)
Equivalent to (and list (satisfies proper-list-p))
. ELEMENT-TYPE
is just ignored.
Examples:
(typep '(1 2 3) '(proper-list integer)) => T
(typep '(1 2 3) '(proper-list string)) => T
property-list-p object
Returns true if OBJECT is a property list.
Examples:
(property-list-p 1) => NIL
(property-list-p '(1 2 3)) => NIL
(property-list-p '(foo)) => NIL
(property-list-p nil) => T
(property-list-p '(foo 1)) => T
(property-list-p '(:a 1 :b 2)) => T
property-list &optional (value-type '*)
Equivalent to (and list (satisfies
property-list-p))
. VALUE-TYPE is just ignored.
Examples:
(typep '(:a 1 :b 2) '(property-list integer)) => T
(typep '(:a 1 :b 2) '(property-list string)) => T
association-list-p var
Returns true if OBJECT is an association list.
Examples:
(association-list-p 1) => NIL
(association-list-p '(1 2 3)) => NIL
(association-list-p nil) => T
(association-list-p '((foo))) => T
(association-list-p '((:a . 1) (:b . 2))) => T
association-list &optional (key-type '*) (value-type '*)
Equivalent to (proper-list (cons KEY-TYPE VALUE-TYPE))
. KEY-TYPE
and VALUE-TYPE are just ignored.
Examples:
(typep '((:a . 1) (:b . 2)) '(association-list integer)) => T
(typep '((:a . 1) (:b . 2)) '(association-list string)) => T
tuplep object
Returns true if OBJECT is a tuple, meaning a proper list.
Examples:
(tuplep 1) => NIL
(tuplep '(1 . 2)) => NIL
(tuplep nil) => T
(tuplep '(1 2 3)) => T
tuple &rest element-types
Equivalent to (and list (cons ARG1 (cons ARG2 (cons ARG3 ...))))
where ARGn is each element of ELEMENTS-TYPES.
Examples:
(typep 1 'tuple) => NIL
(typep '(1 . 2) 'tuple) => NIL
(typep '(1 2 3) 'tuple) => NIL
(typep '(1 2 3) '(tuple integer integer)) => NIL
(typep '(1 2 3) '(tuple string integer integer)) => NIL
(typep nil 'tuple) => T
(typep nil '(tuple)) => T
(typep '(1 2 3) '(tuple integer integer integer)) => T
character-designator
function-designator
file-position-designator
list-designator
package-designator
pathname-designator
stream-designator
string-designator
file-associated-stream-p stream
Returns true if STREAM is a stream associated to a file.
file-associated-stream
Equivalent to (and stream (satisfies file-associated-stream-p))
.
non-nil &optional type
Equivalent to (and (not null) TYPE)
if TYPE is given,
otherwise (not null)
.
Examples:
(typep nil '(non-nil symbol)) => NIL
type-specifier-p type-specifier
Returns true if TYPE-SPECIFIER is a valid type specfiier.
type-expand type-specifier &optional env
Expand TYPE-SPECIFIER in the lexical environment ENV.
LLGPL