Table of Contents
1 petty-types
A tiny library that provides
type-specifier-p
a predicate that checks whether its argument is a valid type specifier(list-of type &optional len)
DEFTYPE for a LIST of elements with TYPE(vector-of type &optional len)
DEFTYPE for a VECTOR of elements with TYPE(tuple &rest types)
DEFTYPE for a list of exactly TYPES(table from to)
DEFTYPE for a hashtableHere are some examples:
> (typep (list 1 2 3 4) '(list-of real)) T > (typep (list 1 2 3 4 3 2 1) '(list-of real)) T > (typep (list 1 2 3 4) '(list-of real 4)) T > (typep (list 1 2 #C(0 1)) '(list-of real)) NIL > (typep (list 1 2 3 4) '(list-of real 5)) NIL > (typep "aaabbb" '(vector-of (member #\a #\b))) T > (typep "aacabbb" '(vector-of (member #\a #\b))) NIL > (typep "aaabbb" '(vector-of (member #\a #\b) 6)) T > (typep "aaaabbb" '(vector-of (member #\a #\b) 6)) NIL > (typep "4aabbb" '(vector-of (member #\a #\b) 6)) NIL > (typep "aabbba" '(vector-of (member #\a #\b) 6)) T ;; THIS IS ESPECIALLY ANNOYING: > (type-of "abab") (SIMPLE-ARRAY CHARACTER (4)) > (typep "abab" '(simple-array (member #\a #\b) (4))) NIL ;; but as above, VECTOR-OF works. > (typep "abab" '(vector-of (member #\a #\b) 4)) T ;; here is an example of TUPLE > (typep '(1 #\x nil :foo) '(tuple fixnum character null keyword)) T > (typep '(1 #\x nil xxx) '(tuple fixnum character null keyword)) NIL ; Because XXX is not a KEYWORD
Created: 2024-09-14 Sat 10:06