What is the equivalent of Lisp's caddr in Clojure?
caddr in Lisps is often used in a manner that amounts to destructuring. Clojure has ubiquitous support for destructuring, so caddr is less useful.
(let [[_ _ x] [1 2 3 4]]
x) ;; -> 3
EDIT: In response to @4bu3li.
(defn describe-path [[first :as edge]]
`(there is a ~(last edge) going ~first from here.))
There is no way to specify the last element w/ destructuring, but that's not really related to the original question anyway.
As caddr
is equivalent to third
in Common Lisp, the closest I see in Clojure is nth
:
(nth collection 2)
It's more generic than caddr
, in that it aspires to work on more structures that cons cell chains. Note, though, that's it's not a place as it is in Common Lisp.
Usually when I need to map a concept from one language to another, I check http://hyperpolyglot.org/
Clojure is included on the Lisp page: http://hyperpolyglot.org/lisp
From this, it appears that there is no direct analogue to caddr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With