I'm writing a function that detects if the argument passed is not a
list, or a is an empty list, or everything else, and I'm getting a
warning back from SBCL that makes no sense to me. Any help interpreting
this is welcome:
CL-USER> (defun p (s)
(let ((x 99))
(cond
((equalp s NIL) (setf x 0))
((not (listp s)) (setf x 1))
(t (format t (setf x 2))))
x))
; in: LAMBDA NIL
; (FORMAT T (SETF X 2))
;
; note: deleting unreachable code
;
; caught WARNING:
; Asserted type (OR (VECTOR NIL) BASE-STRING FUNCTION) conflicts with
derived
; type (VALUES (INTEGER 2 2) &OPTIONAL).
; See also:
; The SBCL Manual, Node "Handling of Types"
; compilation unit finished
; caught 1 WARNING condition
; printed 1 note
STYLE-WARNING: redefining P in DEFUN
P
CL-USER>
What does this mean? What's wrong with my code?
TIA
From: M Jared Finder
Subject: Re: Need help with cryptic sbcl warning
Date:
Message-ID: <424ad27e_3@x-privat.org>
Rusty Shackleford wrote:
> I'm writing a function that detects if the argument passed is not a
> list, or a is an empty list, or everything else, and I'm getting a
> warning back from SBCL that makes no sense to me. Any help interpreting
> this is welcome:
>
> CL-USER> (defun p (s)
> (let ((x 99))
> (cond
> ((equalp s NIL) (setf x 0))
> ((not (listp s)) (setf x 1))
> (t (format t (setf x 2))))
> x))
> ; in: LAMBDA NIL
> ; (FORMAT T (SETF X 2))
> ;
> ; note: deleting unreachable code
> ;
> ; caught WARNING:
> ; Asserted type (OR (VECTOR NIL) BASE-STRING FUNCTION) conflicts with
> derived
> ; type (VALUES (INTEGER 2 2) &OPTIONAL).
> ; See also:
> ; The SBCL Manual, Node "Handling of Types"
> ; compilation unit finished
> ; caught 1 WARNING condition
> ; printed 1 note
> STYLE-WARNING: redefining P in DEFUN
> P
> CL-USER>
>
> What does this mean? What's wrong with my code?
You are passing the integer two (from SETF) as FORMAT's control string.
Instead do (format t "~A" (setf x 2)) or (princ (setf x 2)).
-- MJF
Rusty Shackleford <··@natchie.mine.nu> writes:
> (format t (setf x 2))
[...]
> ; in: LAMBDA NIL
> ; (FORMAT T (SETF X 2))
> ;
> ; note: deleting unreachable code
> ;
> ; caught WARNING:
> ; Asserted type (OR (VECTOR NIL) BASE-STRING FUNCTION) conflicts with
> derived
> ; type (VALUES (INTEGER 2 2) &OPTIONAL).
The second argument to FORMAT should be a format-control. The glossary
defines it as:
format control n. a format string, or a function that obeys the
argument conventions for a function returned by the formatter
macro.
So, the "Asserted type" part is trying to tell you that SBCL demands a
string or a function as the second argument, but the "derived type"
part says that you are providing something that doesn't match, because
2 is not a string or a function.
Zach
From: Eduardo Muñoz
Subject: Re: Need help with cryptic sbcl warning
Date:
Message-ID: <u64z92hsq.fsf@terra.es>
* Rusty Shackleford <··@natchie.mine.nu>
| I'm writing a function that detects if the argument passed is not a
| list, or a is an empty list, or everything else, and I'm getting a
| warning back from SBCL that makes no sense to me. Any help interpreting
| this is welcome:
|
| CL-USER> (defun p (s)
| (let ((x 99))
| (cond
| ((equalp s NIL) (setf x 0))
| ((not (listp s)) (setf x 1))
| (t (format t (setf x 2))))
| x))
| ; in: LAMBDA NIL
| ; (FORMAT T (SETF X 2))
| ;
| ; note: deleting unreachable code
| ;
| ; caught WARNING:
| ; Asserted type (OR (VECTOR NIL) BASE-STRING FUNCTION) conflicts with
| derived
| ; type (VALUES (INTEGER 2 2) &OPTIONAL).
| ; See also:
| ; The SBCL Manual, Node "Handling of Types"
| ; compilation unit finished
| ; caught 1 WARNING condition
| ; printed 1 note
| STYLE-WARNING: redefining P in DEFUN
| P
| CL-USER>
From the hyperspec:
"Function FORMAT
Syntax:
format destination control-string &rest args => result
Arguments and Values: ..."
See the second argument of format is a control-string (a
thing that (setf x 2) is not).
To SBCL hackers while we are at it: The asserted type (or
(vector nil) ...) seems weird to me. AFAIK you consider
(vector nil) a subtype of string but it cant (I think) be
a control string since it can not hold any
characters. Deftype'ing the set of strings that are not of
type (vector nil) may be useless but there is the thought.
--
Eduardo Mu�oz | (prog () 10 (print "Hello world!")
http://213.97.131.125/ | 20 (go 10))
From: Christophe Rhodes
Subject: Re: Need help with cryptic sbcl warning
Date:
Message-ID: <sqsm2d6mbd.fsf@cam.ac.uk>
Eduardo Muñoz <······@terra.es> writes:
> To SBCL hackers while we are at it: The asserted type (or
> (vector nil) ...) seems weird to me. AFAIK you consider
> (vector nil) a subtype of string but it cant (I think) be
> a control string since it can not hold any
> characters. Deftype'ing the set of strings that are not of
> type (vector nil) may be useless but there is the thought.
Formally,
(format nil (make-array 0 :element-type nil))
is valid and returns a freshly-allocated empty string.
(Aside: so is
(format (make-array 0 :element-type nil :adjustable t :fill-pointer 0)
"")
but current bugs in SBCL are exposed by this form)
Christophe