weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 174 forks source link

Allow vectors to be used instead of lists #130

Closed sdegutis closed 8 years ago

sdegutis commented 8 years ago

Hope this isn't a duplicate, I searched the issues for this and nothing relevant seemed to come up.

Currently, if the thing is a vector, then the first element must be a tag name. If you want it to just be a collection of items, you have to return a list or lazy sequence.

But (list) gets ugly. Why not instead just switch off based on the first element? If it's a keyword then you know it's an element, otherwise if it's sequential? then this vector is just a collection of other elements.

weavejester commented 8 years ago

I don't think the additional ambiguity and complexity is worth the benefits. Currently we know that if a value is a vector, it's an element, and if it's a seq, it's expanded. Checking the first element of a vector would complicate the compiler, increase the possibility of user errors, and it would be harder to spot expanded seqs at a glance.

In my experience, list isn't used enough to warrant the disadvantages of introducing a new vector syntax. Expanded seqs are typically from forms like for and map; using list is a fairly rare occurrence, as it almost always makes more sense to wrap a returned value in a containing element than to return a bare list of elements.