Re: Problem with type conflict style warning

steve gonedes <[email protected]>
Newsgroups gmane.lisp.steel-bank.general
Message-ID <[email protected]>
On 5/15/24 8:11 AM, syll-dev wrote:
> Hello
>
> I don't understand this style warning...
>
> Here is the code (problem with test1 only) :
> "
> (ql:quickload :alexandria)
> (use-package :alexandria)
>
> (defvar *l* '(1 2 3))
>
> (defun test1 ()
>    (copy-sequence 'vector (reverse *l*)))
>
> (defun test2 ()
>    (copy-sequence 'vector *l*))
>
> (defun test3 ()
>    (copy-sequence 'vector '(1 2 3)))
>
> (defun test4 ()
>    (let ((l '(1 2 3)))
>      (copy-sequence 'vector l)))
> "
>
> And here is the result :
> "
> ; in: DEFUN TEST1
> ;     (COPY-SEQUENCE 'VECTOR (REVERSE *L*))
> ; --> BLOCK IF COERCE
> ; ==>
> ;   1
> ;
> ; caught STYLE-WARNING:
> ;   Derived type of SB-C::X is
> ;     (VALUES (OR LIST SB-KERNEL:EXTENDED-SEQUENCE) &OPTIONAL),
> ;   conflicting with its asserted type
> ;     VECTOR.
> ;   See also:
> ;     The SBCL Manual, Node "Handling of Types"
> "
>
> sbcl 2.4.1 and 2.4.4 (other versions not tested).
>
> I have the same problem with remove-if-not instead of reverse.
>
> Thank you
>
> syll
>
>
the function copy-sequence is in alexandria.


(defun copy-sequence (type sequence)
   "Returns a fresh sequence of TYPE, which has the same elements as
SEQUENCE."
   (if (typep sequence type)
       (copy-seq sequence)
       (coerce sequence type)))


Here are some easy ones.

;;;; coerce

(defparameter lst (list 1 2 3))

(defun list-to-vector (lst)
   (apply #'vector lst))

(defun list-to-vector-coerce (lst)
   (coerce lst 'vector))

(list-to-vector-coerce lst)
=> #(1 2 3)

(reverse #(1 2 3))
(reverse (list 1 2 3 4))


(remove-if-not #'oddp #(1 2 3 4 5))
(remove-if #'evenp (list 1 2 3 4 5))

=> (1 3 5)

I usually stay away from the external packages. it's a pain in the a$$ .

The problem as I see it. vectors look like #(1 2 3 4) lists look like (1 
2 3 4),

notice the #






_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.