4
votes

I am very new to clojure and the syntax is pretty rough. I'm trying to destructure a vector of vectors.

This is the output from a function I use: [[:b 2 3] [:b 3 7] [:b 9 8]]

But, what I would like it to do is display the output like so: [:b 2 3] [:b 3 7] [:b 9 8]

Basically, trying to get rid of those out-most brackets. Is this possible? Any help is appreciated :)

1
Are you happy with the function returning a vector of vectors? When you say you want it to display without the outer-most brackets, do you mean that you want to "print" the vector of vectors to screen without the outer-most brackets?ToBeReplaced

1 Answers

3
votes

If you just want the specified output, you can certainly massage things that way:

(apply str (interpose " " [[:b 2 3] [:b 3 7] [:b 9 8]]))
;= "[:b 2 3] [:b 3 7] [:b 9 8]"

does the trick. As for destructuring, if you had a function f which returned [[:b 2 3] [:b 3 7] [:b 9 8]], you could use destructuring as follows:

(defn f []  ;; something presumably more complicated goes here
    [[:b 2 3] [:b 3 7] [:b 9 8]])

(let [[a b c] (f)]
    (println a b c))
; prints [:b 2 3] [:b 3 7] [:b 9 8]