How can I avoid the nil printed in the end?

后端 未结 2 1168
逝去的感伤
逝去的感伤 2021-01-22 13:31

I have coded this function that prints-out the state of the board, but in the end, due to the fact that there isnt no return the function prints an nil!

Function:

<
2条回答
  •  爱一瞬间的悲伤
    2021-01-22 13:55

    You can get rid of multiple formats in the code:

    Usually in a functional language I would return a value. It makes sense to return the board itself. Since such a function is usually called from game logic, a return value may be useful and it does not matter for output then.

    (defun show-board (board)
      (dotimes (i 8)
        (dotimes (j 8)
          (write-string (case (aref board i j)
                          (0         "B ")
                          (1         "P ")
                          (otherwise "L "))))
        (terpri))
      board)
    

提交回复
热议问题