Reputation: 113
Although my question seems to be concerned with a rather trivial task, I was not yet able to sucessfully create a single 2-dimensional vector
[[1 2] [3 4]]
fom two individual vectors,
(def a [1 2])
and (def b [3 4])
.
Leaving the functions conj
and cons
aside, I ran into the problem that vec
or into-array
both expect single input values.
Another workaround would be pre-filling a two dimenstional vector
(vec (replicate 2 (vec (replicate 2 nil))))
but I it is still a complicated option.
Upvotes: 0
Views: 87
Reputation: 50017
There are several ways to approach this:
vector
: (vector a b) => [[1 2] [3 4]])
conj
: (conj [] a b) => [[1 2] [3 4]]
[a b] => [[1 2] [3 4]]
If Clojure has a problem it is an excess of riches. :-)
Upvotes: 4
Reputation: 7568
Just use vector
:
(def a [1 2])
(def b [3 4])
(vector a b) => [[1 2] [3 4]]
[a b] => [[1 2] [3 4]]
Upvotes: 4