Forum: Editorial
References: apply
Category: CLARIFICATION/CHANGE
Edit history: 2011-01-02, Version 3 by Dave Fox
Status: For CLiki consideration
- Problem Description:
- This example for APPLY is wrong, because it assumes particular behavior of TYPE-OF:
(defun foo (size &rest keys &key double &allow-other-keys)
(let ((v (apply #'make-array size :allow-other-keys t keys)))
(if double (concatenate (type-of v) v v) v)))
(foo 4 :initial-contents '(a b c d) :double t)
=> #(A B C D A B C D)
The call to FOO will signal an error if TYPE-OF returns a type containing the length (4). This causes a type conflict in CONCATENATE, because the new sequence length should be 8. (If TYPE-OF returns a type without the length, then FOO will behave as shown above.)(concatenate `(vector ,(array-element-type v) *) v v) (concatenate `(vector ,(array-element-type v) ,(* 2 size)) v v)