(cond
((and (not (eq spec u))
(info :type :builtin spec)))
+ ((and (consp spec) (symbolp (car spec))
+ (info :type :builtin (car spec))
+ (let ((expander (info :type :expander (car spec))))
+ (and expander (values-specifier-type (funcall expander spec))))))
((eq (info :type :kind spec) :instance)
(find-classoid spec))
((typep spec 'classoid)
(values nil nil))
((symbolp spec)
(values (info :type :expander spec) (list spec)))
+ ((and (consp spec) (symbolp (car spec)) (info :type :builtin (car spec)))
+ ;; see above
+ (values nil nil))
((and (consp spec) (symbolp (car spec)))
(values (info :type :expander (car spec)) spec))
(t nil)))
"Return a sequence of the given TYPE and LENGTH, with elements initialized
to INITIAL-ELEMENT."
(declare (fixnum length))
- (let* ((adjusted-type
- (typecase type
+ (let* ((expanded-type (typexpand type))
+ (adjusted-type
+ (typecase expanded-type
(atom (cond
- ((eq type 'string) '(vector character))
- ((eq type 'simple-string) '(simple-array character (*)))
+ ((eq expanded-type 'string) '(vector character))
+ ((eq expanded-type 'simple-string) '(simple-array character (*)))
(t type)))
(cons (cond
- ((eq (car type) 'string) `(vector character ,@(cdr type)))
- ((eq (car type) 'simple-string)
- `(simple-array character ,(if (cdr type)
- (cdr type)
+ ((eq (car expanded-type) 'string) `(vector character ,@(cdr expanded-type)))
+ ((eq (car expanded-type) 'simple-string)
+ `(simple-array character ,(if (cdr expanded-type)
+ (cdr expanded-type)
'(*))))
(t type)))
(t type)))
(error ()
:error))))))
\f
+;;; tests of deftype types equivalent to STRING or SIMPLE-STRING
+(deftype %string () 'string)
+(deftype %simple-string () 'simple-string)
+(deftype string-3 () '(string 3))
+(deftype simple-string-3 () '(simple-string 3))
+
+(with-test (:name :user-defined-string-types-map-etc)
+ (dolist (type '(%string %simple-string string-3 simple-string-3))
+ (assert (string= "foo" (coerce '(#\f #\o #\o) type)))
+ (assert (string= "foo" (map type 'identity #(#\f #\o #\o))))
+ (assert (string= "foo" (merge type '(#\o) '(#\f #\o) 'char<)))
+ (assert (string= "foo" (concatenate type '(#\f) "oo")))
+ (assert (string= "ooo" (make-sequence type 3 :initial-element #\o)))))
+(with-test (:name :user-defined-string-types-map-etc-error)
+ (dolist (type '(string-3 simple-string-3))
+ (assert (raises-error? (coerce '(#\q #\u #\u #\x) type)))
+ (assert (raises-error? (map type 'identity #(#\q #\u #\u #\x))))
+ (assert (raises-error? (merge type '(#\q #\x) "uu" 'char<)))
+ (assert (raises-error? (concatenate type "qu" '(#\u #\x))))
+ (assert (raises-error? (make-sequence type 4 :initial-element #\u)))))
+
;;; success