FWIW, the same is true for the inverse operation. If you pop an item off a list you’ll get the list, less the item you conj’d. Same is true with a vector.
--- Joe R. Smith [email protected] <mailto:[email protected]> @solussd On Jul 16, 2018, at 4:31 PM, Alex Miller <[email protected] <mailto:[email protected]> > wrote: On Monday, July 16, 2018 at 4:08:47 PM UTC-5, solussd wrote: Another way to think about it is lists and vectors are different and the idiomatic way to add items to them is different. I would say different data structures have different ways to *efficiently* add items to them, and conj is an operation to add items efficiently (meaning, sub-linear time). So when you see conj, you know it is always a "fast" operation. A (singly-linked) list is usually prepended to (otherwise you have to walk the entire list to find the end). A vector is usually added to at it’s n+1 index, where n is the size of the vector. The conj function is polymorphic. cons takes a seq and returns a seq. It only cares that it can get a seq on whatever collection you give it and will always prepend to that seq. Slight modification - I would say cons takes a *seqable* and returns a seq. For example, a vector is seqable, but not a seq. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] <mailto:[email protected]> Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] <mailto:[email protected]> For more options, visit this group at http://groups.google.com/group/clojure?hl=en <http://groups.google.com/group/clojure?hl=en> --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]> . For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
