From: Raymond Toy
Subject: Two bugs in cmulisp 17f
Date: 
Message-ID: <4n3f3p82vj.fsf@rcur18.i-have-a-misconfigured-system-so-shoot-me>
While working on some stuff, I came across what appear to be two bugs
in CMU Lisp 17f.

1.  (coerce 0.0 '(complex single-float)) doesn't work but (coerce 0.0
    'complex) does.  (This also fails for any more specific complex
    type.)  Also, (coerce 0 'complex) fails.  My reading of CLtL 2
    says it should probably return 0 instead of #C(0 0) by complex
    rationalization (?).

    Any solution for this?

2.  (make-sequence '(vector float) n) fails because
    make-sequence tries to initialize the vector with 0 instead of
    0.0.  Here is a my replacement for make-sequence, complicated by
    the fact that (coerce 0.0 '(complex single-float)) doesn't work as
    expected.  I took this from the CMU sources and modified that last
    part to coerce 0 to the appropriate numerical type.

(defun make-sequence (type length &key (initial-element NIL iep))
  "Returns a sequence of the given Type and Length, with elements initialized
  to :Initial-Element."
  (declare (fixnum length))
  (let ((type (kernel::type-expand type)))
    (cond ((subtypep type 'list)
           (make-list length :initial-element initial-element))
          ((subtypep type 'string)
           (if iep
               (make-string length :initial-element initial-element)
               (make-string length)))
          ((subtypep type 'simple-vector)
           (make-array length :initial-element initial-element))
          ((subtypep type 'bit-vector)
           (if iep
               (make-array length :element-type '(mod 2)
                           :initial-element initial-element)
               (make-array length :element-type '(mod 2))))
          ((subtypep type 'vector)
           (if (listp type)
               (if iep
                   (make-array length :element-type (cadr type)
                               :initial-element initial-element)
                   (make-array length :element-type (cadr type)
                               :initial-element
                               (if (subtypep (cadr type) 'number)
				   ;; Handle the case of complex
				   ;; numbers.  We have to watch out
				   ;; for the case of complex and the
				   ;; specialized versions of complex
				   ;; like (complex single-float).  We
				   ;; need to do this because (coerce
				   ;; 0.0 '(complex single-float))
				   ;; doesn't work!
				   (if (subtypep (cadr type) 'complex)
				       (if (consp (cadr type))
					   ;; Make the right type of complex
					   (complex (coerce 0 (cadadr type)))
					   ;; Generic complex
					   (coerce 0.0 (cadr type)))
				       ;; Non complex number
				       (coerce 0 (cadr type)))
                                   NIL)))
               (make-array length :initial-element initial-element)))
          (t (error "~S is a bad type specifier for sequences." type)))))

Ray

--