3 ms·
If object-oriented programmers (here represented by Scala-ites) are excessively fond of modelling the crap out of stuff, to the detriment of the code they're tr
by mcguire 13y ago
If object-oriented programmers (here represented by Scala-ites) are excessively fond of modelling the crap out of stuff, to the detriment of the code they're trying to write, there is also a problem with the opposite, "lightweight data modelling" approach: a weird fascination with representations of data, instead of the structure of it.
Here's an example from Land of Lisp:
(defun limit-tree-depth (tree depth)
(list (car tree)
(cadr tree)
(if (zerop depth)
(lazy-nil)
(lazy-mapcar (lambda (move)
(list (car move)
(limit-tree-depth (cadr move) (1- depth))))
(caddr tree)))))
and here's the version that I re-wrote, using your friend and mine, defstruct:
(defun limit-tree-depth (tree depth)
(labels ((limit-depth-move (move)
(let* ((next-tree (limit-tree-depth (get-tree move) (1- depth))))
(if (passing-move-p move)
(make-passing-move :tree next-tree)
(make-attacking-move :src (attacking-move-src move)
:dst (attacking-move-dst move)
:tree next-tree)))))
(make-tree-node :player (tree-node-player tree)
:board (tree-node-board tree)
:moves (if (zerop depth)
(lazy-nil)
(lazy-mapcar #'limit-depth-move
(tree-node-moves tree))))))
I submit that the second may be preferable, even if it is a bit more verbose.
- lispm 13y agoagreed