Another way to think about it is lists and vectors are different and the 
idiomatic way to add items to them is different. 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.

On Jul 16, 2018, at 3:15 PM, Christian Seberino <cseber...@gmail.com 
<mailto:cseber...@gmail.com> > wrote:

I'm impressed with Clojure syntax and I'm still a beginner.

I noticed conj behaves differently for lists and vectors.  I also noticed cons 
does not return a vector for a vector input.

Is there any downside to make 2 macros...prepend and append that behave the 
same for lists and vectors, and also,
return same types as inputs?

If I'm not mistaken, I believe it is for performance reasons that these are not 
already in the standard language?
For those that care about performance, it would be beholden on them to pick the 
correct macro for their
specific data structure.

Good idea?

Thanks!

Chris



-- 
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 
<mailto: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 
<mailto:clojure+unsubscr...@googlegroups.com> 
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 clojure+unsubscr...@googlegroups.com 
<mailto:clojure+unsubscr...@googlegroups.com> .
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 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.

Reply via email to