Lisp/Clojure で書くコードの行数を減らすことが私の強迫観念になりました。次のコード (基本的に深さ優先検索) を短くしようとしています。
(defn find-node [nodeid in-node]
(if (= nodeid (:id in-node))
in-node
(loop [node nil activities (:activities in-node)]
(if (or (empty? activities) (not (nil? node)))
node
(recur (find-node nodeid (first activities)) (rest activities))))))
(defn find-node-in-graph [nodeid node activities]
(if (empty? activities)
node
(recur nodeid (find-node nodeid (first activities)) (rest activities))))
(defrecord Graph [id name activities])
(defrecord Node [id name activities])
「活動」はリストです