I found this question interesting for two reasons:

(1) A selected item has been specified which needs to be handled
differently - at first glance suggests an iterative solution.
(2) There is good support for html in clojure via libraries, so you
should avoid string concatenation of tags.

So here is my solution:
http://groups.google.com/group/clojure/web/layout.clj

Notably it bolds the selected item without any iteration, and returns
a list representation of the html instead of a string. I'm not
familiar with the html libraries to render this representation so
forgive any inconsistencies there, but the output is:

(:table (:tr (:item (:bold "cat")) (:item "dog") (:item "")) (:tr
(:item "rabbit") (:item "frog") (:item "elephant")))
Which will be validated by the rendering library, giving an additional
security that it is correct.

In order to deal with the 'selected item' I had to jump through some
hoops to treat collections as vectors and use assoc on that. Is there
perhaps a more elegant way? Overall though I hope it is a good example
of how and why it is a good idea to avoid string catting and instead
think of the problem in terms of creating a structure.

Really you are building a tree based upon some inputs. I'd be
interested in other ways the tree could be constructed.


Regards,
Tim.


--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to