In article <·················@netcom.com>,
Bill Newman <·······@netcom.com> wrote:
>I received e-mail suggesting -- if I understood correctly -- that I
>can't overload assignment in Lisp, but the same effect could be
>achieved by defining my own (REVERSIBLE-ASSIGN VAR VALUE) function or
>macro in Lisp. I can't figure out how to do even this.
Here's a quick implementation:
(defparameter *undo-setq-table*
(make-hash-table :test #'eq))
(defmacro undoable-setq (var value)
`(progn (push ,var (gethash ',var *undo-setq-table*))
(setq ,var ,value)))
(defmacro undo-setq (var)
`(setq ,var (pop (gethash ',var *undo-setq-table*))))
Of course, for your Go application you'd have to extend this to store
the differences between the arrays representing boards, rather than
the arrays themselves.
>Also, even if I
>could, I'd still prefer to have the reversible-ness associated with
>each variable, rather than with each assignment to each variable. (I
>used to do it the other way around in C before I switched to C++, and
>it was a major maintenance hassle tracking down things which
>accidentally changed something irreversibly.)
Hmm... I would have imagined that there would be only one place in
your code where you change the board -- the function where you
calculate the effect of a player placing a piece on the board.
--
== Seth Tisue <·······@nwu.edu> http://www.cs.nwu.edu/~tisue/