Mistake in destructuring-pair??
Closed this issue · 1 comments
genovese commented
The definition of destructuring-pair?
looks like it is missing something in the second clause:
(defn- pair? [x] (and (vector? x) (= 2 (core/count x))))
(defn- destructuring-pair? [x]
(and (pair? x) (not (or (keyword? x) (= '& x)))))
[Lines 30-32 in current version.]
If pair? x
is true, then x
is certainly not a keyword or a symbol, so the second clause is automatically true, obviating the need for the function. Should the second clause be replaced with (not (some #(or (keyword? %) (= '& %)) x))
, or perhaps (not (or (some keyword? x) (= '& (first x))))
if preferred for your intent?
imrekoszo commented
It appears to me that the second clause in the and
should check the first element of x. The only two-element destructuring vectors I currently am aware of are:
(let [[& foo] (range 10)
[:as bar] (range 5)])