Subject: Re: please review my new *working* code - now with 20% more oop!
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 23 Feb 2009 21:25:16 -0600
Newsgroups: comp.lang.lisp
Message-ID: <oIGdnapotroB9T7UnZ2dnUVZ_hKWnZ2d@speakeasy.net>
Oops! I just wrote:
+---------------
| Or more straightforwardly [IMHO!]:
| 
|     (defvar *a* (make-instance 'chessboard))
| 
|     (loop for piece in '(wk wb wn bk)
|           and (rank column) in (mapcar #'rank-file (get-positions))
|       do (put-piece *a* rank column piece))
+---------------

Silly me! Why invent yet another name to confuse the reader of
one's code when the proper name is staring one right in the face?!?
Given that there is alread a function called #'RANK-FILE, *of course*
the destructuring temp should have been named FILE instead of COLUMN:

    (loop for piece in '(wk wb wn bk)
          and (rank file) in (mapcar #'rank-file (get-positions))
      do (put-piece *a* rank file piece))

Afterthought: The fact that one has to "know" that #'GET-POSITIONS
returns things in the order "WK WB WN BK" makes me uncomfortable.
It's too easy for it to get out of sync as the program evolves.
I'd feel a lot better about this whole thing if the values that
#'GET-POSITIONS returned had the piece name inside and if there were
a #'RANK-FILE-PIECE function so one could simply write this instead:

    (loop for (rank file piece) in (mapcar #'rank-file-piece (get-positions))
      do (put-piece *a* rank file piece))

Or, if you don't like LOOP:

    (dolist (position (get-positions))
      (destructuring-bind (rank file piece)
	  (rank-file-piece position)
	(put-piece *a* rank file piece)))


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607