I want to write Lisp code like this
(defstruct board (size 7) (matrix (make-array (list size size)) (red-stones 0) (black-stones 0))
to determine the structure representing the playing field.
I want to be able to create a new board with a breadboard that will create a matrix on the fly with a given size (size x size), so I do not need to call the make-board from another function that makes the matrix.
However, when I load this code into the clisp interpreter and try to create a new board (with make-board), I get an error message telling me that "size" does not matter.
Can structure fields be used in the structure definition itself?
Or should I do this?
(defstruct board size matrix (red-stones 0) (black-stones 0)) (defun create-board (size) (make-board :size size :matrix (make-array (list size size))) )
Indeed, I do not like the availability of both a finished board and a created board, because this can lead to programming errors.
Genba source share