james
9/30/2015 9:21:00 AM
On Wednesday, September 30, 2015 at 4:59:58 PM UTC+8, CAI GENGYANG wrote:
> Strangely enough, when i ran your original piece of code, it worked for me :
>
>
> CL-USER 1 > (defun by_with_wraper (n_wraper exchange)
> (let ((var (floor n_wraper exchange))
> (n_choco 0))
> (incf n_choco (nth-value 0 var))
> (if (> n_choco 0)
> (by_with_wraper (+ n_choco (nth-value 1 var)) exchange)
> (return-from by_with_wraper n_choco))))
> BY_WITH_WRAPER
>
>
>
>
> On Wednesday, September 30, 2015 at 4:47:53 PM UTC+8, james wrote:
> > Here is my code which will get compilation error
> >
> > (defun by_with_wraper (n_wraper exchange)
> > (let ((var (floor n_wraper exchange))
> > (n_choco 0))
> > (incf n_choco (nth-value 0 var))
> > (if (> n_choco 0)
> > (by_with_wraper (+ n_choco (nth-value 1 var)) exchange)
> > (return-from by_with_wraper n_choco))))
> >
> >
> > test.lisp:212:25:
> > note: deleting unreachable code
> > warning:
> > Derived type of #:KEEPER2 is
> > (VALUES NULL &OPTIONAL),
> > conflicting with its asserted type
> > NUMBER.
> > See also:
> > SBCL Manual, Handling of Types [:node]
> >
> > Compilation failed.
> >
> > But after I change to the following code " (+ n_choco (nth-value 1 var)) ---> (+ n_choco (nth-value 0 var))". Every thing is ok. Any idea about this error?
> >
> > (defun by_with_wraper (n_wraper exchange)
> > (let ((var (floor n_wraper exchange))
> > (n_choco 0))
> > (incf n_choco (nth-value 0 var))
> > (if (> n_choco 0)
> > (by_with_wraper (+ n_choco (nth-value 0 var)) exchange); Here is the difference
> > (return-from by_with_wraper n_choco))))
I think i got the reason. By doing this (var (floor n_wraper exchange),var is a integer but not a values. I am using sbcl.