Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The equivalent Clojure code is actually a few lines shorter than your example:

    (ns add-nums
      (:use compojure.core [hiccup core page-helpers] ring.adapter.jetty))

    (defroutes handler
      (GET "/add-nums" [a b]
        (let [a (Integer/parseInt a)
              b (Integer/parseInt b)]
          (html
            [:html
              [:head [:title "Add two numbers"]]
              [:body
                (if (and a b) [:p (+ a b)])
                (form-to [:get "/add-nums"]
                  (text-field :a)
                  (text-field :b)
                  (submit-button))]])))

    (run-jetty handler {:port 8080})
Mark's tutorial code is a little more complete than your example, and doesn't aim for brevity. It also doesn't use any of the form functions from Hiccup (admittedly, they're not as well documented as they could be).


Finally, an actual programmer's response.

Thank you! It's good to know that verbosity was for the sake pedagogy and completeness, and not necessity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: