I am trying to create a table (work schedule) that I previously encoded using python, I think this will be a good introduction to the Clojure language for me.
I have very little experience with Clojure (or lisp for that matter), and I did my google rounds and a good bit of trial and error, but it seems to have coding.
Here is my sample data (in the future, it will come from the sqlite database):
(def smpl2 (ref {"Salaried" [{"John Doe" ["12:00-20:00" nil nil nil "11:00-19:00"]} {"Mary Jane" [nil "12:00-20:00" nil nil nil "11:00-19:00"]}] "Shift Manager" [{"Peter Simpson" ["12:00-20:00" nil nil nil "11:00-19:00"]} {"Joe Jones" [nil "12:00-20:00" nil nil nil "11:00-19:00"]}] "Other" [{"Super Man" ["07:00-16:00" "07:00-16:00" "07:00-16:00" "07:00-16:00" "07:00-16:00"]}]}))
I tried to do this first with for , then moved to a dose and finally domap (which seems more successful) and dumping the contents into an html table (my source python program output this from sqlite database to Excel table using COM).
Here is my attempt (create-table fn):
(defn html-doc [title & body] (html (doctype "xhtml/transitional") [:html [:head [:title title]] [:body body]])) (defn create-table [] [:h1 "Schedule"] [:hr] [:table (:style "border: 0; width: 90%") [:th "Name"][:th "Mon"][:th "Tue"][:th "Wed"] [:th "Thur"][:th "Fri"][:th "Sat"][:th "Sun"] [:tr (domap [ct @smpl2] [:tr [:td (key ct)] (domap [cl (val ct)] (domap [c cl] [:tr [:td (key c)]]))]) ]]) (defroutes tstr (GET "/" ((html-doc "Sample" create-table))) (ANY "*" 404))
This prints out a table with sections (salaried, manager, etc.) and section names, I just feel like I am abusing domap by nesting it too many times since I will probably have to add more domaps just to get the switch time in their respective columns, and the code gets a "dirty" feeling.
I apologize in advance if I do not include enough information, I usually do not ask for help on coding, this is also my first question :).
If you know any better approaches to this, or even tips or tricks that I should know as a newbie, they are certainly welcome.
Thanks.
clojure compojure
Kenny164
source share