John Bucher
John Bucher

Reputation: 59

Values-list: a proper list must not end with 1 - nQueens

I asked a question about my nQueens problem the other day and received many great answers so I thought I would ask again since I am very close to finishing this threat function. My function is to determine a threat on the horizontal, vertical, or diagonal. My input is like so:

(THREAT? '(1 3) '((1 0)(2 4)(3 7)(4 3)(5 2)(6 8)(7 5)(8 1)))

It gives a new given position and checks to see if putting it on the board would create any problems. The code I have up to now is as follows:

*I have split diagonal into its own function to make the code a little more readable

(defun diagonal(point1 point2)
    (= (abs (- (values-list ( car point1 )) (values-list (car point2))))
       (abs (- (values-list ( cdr point1 )) (values-list (cdr point2)))))
)

(defun THREAT?(x y)
    ; Checks threat on the vertical
    (when (not (eq (values-list (cdr (nth (- (car x) 1 ) y )) ) '0 ) )
            (return-from THREAT? t)
    )
    (loop for i from 0 to (list-length y)

            ; Checks threat on the horizontal
            when (eq (values-list ( cdr x  )) (values-list (cdr (nth i y))) )
                    do (return-from THREAT? t)
            ; With the help of the diagonal function checks along the diagonal
            when (diagonal x (nth i y) )
                    do (return-from THREAT? t)
    )
)

*The vertical and horizontal functions work fine as I have commented out diagonal and checked the two.

I receive the error message not at compilation but when running my code:

VALUES-LIST: A proper list must not end with 1

which I suspect is a problem in my diagonal function. I don't see why values-list would be a problem since I have used it a couple times in the very same code with no problems. I believe the diagonal function should be given two lists (1 3)(2 4) for example, take the car of each making it (1)(2) and then applying values-list and pulling the values out of the brackets to then be manipulated. Any and all help is greatly appreciated!

Upvotes: 0

Views: 3364

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139251

The idea of using values-list makes no sense at all.

(defun diagonal (point1 point2)
    (= (abs (- (values-list ( car point1 )) (values-list (car point2))))
       (abs (- (values-list ( cdr point1 )) (values-list (cdr point2))))))

Now we call:

(diagonal '(1 3) '(1 0))

point1 is (1 3).

Now you call (CAR '(1 3)). The result is 1. Then you call (VALUES-LIST 1). But why??? (VALUES-LIST 1) does not work, because VALUES-LIST expects a list as an argument. But 1 is not a list, but a number. --> ERROR

VALUES-LIST returns the contents of a list as multiple values. But since your code does not deal with multiple values in any way, it simply makes no sense.

Upvotes: 4

Related Questions