2010-02-06 22:00:08 +00:00
|
|
|
(meditations
|
2010-07-26 23:20:42 +00:00
|
|
|
"You can use vectors in clojure to create an 'Array' like structure"
|
2010-10-27 05:04:32 +00:00
|
|
|
(= __ (.size []))
|
2010-02-06 22:00:08 +00:00
|
|
|
|
2010-10-27 05:04:32 +00:00
|
|
|
"You can create a vector in several ways"
|
2010-09-29 00:18:47 +00:00
|
|
|
(= __ (vec nil))
|
2010-02-06 22:00:08 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"And populate it in either of these ways"
|
2010-09-29 00:18:47 +00:00
|
|
|
(= __ (vec '(1)))
|
2010-02-06 22:00:08 +00:00
|
|
|
|
2010-10-27 05:04:32 +00:00
|
|
|
"There is another way as well"
|
|
|
|
(= __ (vector nil))
|
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"But you can populate it with any number of elements at once"
|
|
|
|
(= [1 __] (vec '(1 2)))
|
2010-02-06 22:00:08 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"And add to it as well"
|
|
|
|
(= __ (conj (vec nil) 333))
|
2010-02-06 22:00:08 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"You can get the first element of a vector like so"
|
2010-09-29 00:18:47 +00:00
|
|
|
(= __ (first [:peanut :butter :and :jelly]))
|
2010-02-06 22:00:08 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"And the last in a similar fashion"
|
|
|
|
(= __ (last [:peanut :butter :and :jelly]))
|
|
|
|
|
|
|
|
"Or any index if you wish"
|
|
|
|
(= __ (nth [:peanut :butter :and :jelly] 3))
|
|
|
|
|
|
|
|
"You can also slice a vector"
|
|
|
|
(= __ (subvec [:peanut :butter :and :jelly] 1 3)))
|