Loops with Reflex

Filed under: programming

ghcjs beats bootstrap and jquery for prototyping web design. combining recursion and lamba functions is so awesome! here's how I created 100 list item links numbered in sequential order with 3 lines of code. (using underscores to represent indentation).

forM [1..100]  \item -> el "li"  do
  elAttr "a" ("href" =: "#") 
    text (printf "%03d" (item :: Int))
it produces these DOM elements...
Later on I was told that clojurescript has something similar, using s-expressions to construct the html:
(for [item (range 100)
[:li [:a {:href "#"} (format "%03d" item)]]])