I work with clojure, and while I was doing this with lisps, I was having trouble finding a clean way to nest expressions in cond expressions. For example, consider the following function:
(defn operate-on-list [xs]
(let [[unpack vector] (first xs)]
(cond
[(empty? xs) 'empty
unpack vector
:else (operate-on-list (rest xs))])))
This is a pretty standard recursive operation in a list, but it needs to do some work on the first element in the list before it works with the contents. The problem, of course, is that the list may be empty.
In this example, it's easy to change unpackto ((first xs) 0)and vectorto ((first xs) 1), but it quickly gets ugly if more work is required (xs first).
Is there a way to efficiently use the let statement with cond?
Thanks.
-Nate
source
share