Alex Thanks for all the replies. It is clear there are 2 values in language design...*simplicity* and *efficiency*. Sometimes they conflict unfortunately. Clojure sacrificed a tiny amount of simplicity for a huge gain in efficiency with the design of conj and friends.
Imagine someone wanted to have Clojure compete with Python and Scheme for introductory programming classes. In that space simplicity is everything. Maybe it would make sense there to teach using "prepend" and "append" functions to keep things as simple as possible. Then, later when they were more confident and ready, efficiency considerations and conj could be explained. Would that give the best of both worlds? Everyone could have what they want when they want it. cs On Monday, July 16, 2018 at 4:30:51 PM UTC-5, Alex Miller 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.