Je travaille sur un jeu de tic-tac-toe à deux joueurs, et je suis dans la phase où je travaille toutes les erreurs dans mon code. L'erreur actuelle je suis bloqué sur une erreur illegal function call
dans le code suivant:La fonction illégale appelle en commun Lisp
(cond
[...snip...]
((= CHOICE 3)
(IF (NUMBERP (AREF *BOARD* 0 2))
(SETF (AREF *BOARD* 0 2) *MARKER*)
(INVALID-SELECTION)))
Qu'est-ce que je fais mal?
EDIT La fonction entière ressemble à ceci:
(defun select (choice)
(cond ((= choice 1)
(if (numberp (aref *board* 0 0)) (setf (aref *board* 0 0) *marker*)
(invalid-selection))))
((= choice 2)
(if (numberp (aref *board* 0 1)) (setf (aref *board* 0 1) *marker*)
(invalid-selection))))
((= choice 3)
(if (numberp (aref *board* 0 2)) (setf (aref *board* 0 2) *marker*)
(invalid-selection))))
((= choice 4)
(if (numberp (aref *board* 1 0)) (setf (aref *board* 1 0) *marker*)
(invalid-selection))))
((= choice 5)
(if (numberp (aref *board* 1 1)) (setf (aref *board* 1 1) *marker*)
(invalid-selection))))
((= choice 6)
(if (numberp (aref *board* 1 2)) (setf (aref *board* 1 2) *marker*)
(invalid-selection))))
((= choice 7)
(if (numberp (aref *board* 2 0)) (setf (aref *board* 2 0) *marker*)
(invalid-selection))))
((= choice 8)
(if (numberp (aref *board* 2 1)) (setf (aref *board* 2 1) *marker*)
(invalid-selection))))
((= choice 9)
(if (numberp (aref *board* 2 2)) (setf (aref *board* 2 2) *marker*)
(invalid-selection))))
Cela devrait vous enseigner. N'utilisez jamais copier/coller. Dans ce cas, vous pouvez '(let ((x (floor choice 3)) (y (rem choix 3))) (if (nombre (aref * board * xy)) (setf (aref * tableau * xy) * marqueur *) (invalid-selection))) ', au lieu du long' cond'. Dans d'autres cas, factoriser le code en double dans une fonction ou une macro. – Svante
Si vous connaissez les valeurs multiples, vous pouvez également utiliser directement les deux valeurs de retour de la fonction 'floor':' (multiple-value-bind (x y) (floor choice 3) (si ...)) '. – Svante