Hi

On Tue, Feb 17, 2009 at 4:03 PM, Jesse Aldridge <jessealdri...@gmail.com> wrote:
>
>> Jesse,
>> Could I see your own version.
>
> Haha, I was afraid someone would say this.
> Here is my embarrassingly bad (but working) version:
>
> (defn build-table []
>  (def num-cols 3)
>  (def selected-row 0)
>  (def selected-col 0)
>  (def all-strings ["apple" "cat" "dog" "" "frog" "elephant"
> "gorilla"])

let would be better than def here.  def creates basically a global
variable (although I'm sure someone will complain about me calling
them that :)

>  (defn new_cell [string row col]
>    (defn bg-color []

There's no point using nested defns, since defn is defined in terms of
def.  i.e. these are also global.

>      (if (and (= col selected-col)
>               (= row selected-row))
>        "d0e0ff"
>        "cfcfdf"))
>    (str "<td bgcolor=#" (bg-color) ">" "<font color=#0000cc>"
>         (first string) "</font>" (.substring string 1 (.length
> string))
>         "</td>"))
>
>  (loop [row 0 col 0
>         table_contents "<table cellpadding=30 bgcolor=#6666aa>\n<tr>
> \n"
>         strings all-strings]
>    (if strings
>      (if (not= (first strings) "")
>        (if (>= col num-cols)
>          (recur (inc row) 0 (str table_contents "</tr>\n<tr>")
> strings)
>          (recur row (inc col)
>            (str table_contents (new_cell (first strings) row col))
>            (rest strings)))
>        (recur row col table_contents (rest strings)))
>      (str table_contents "</tr>\n</table>"))))
>
> I actually got it working before reading any of the replies here.  So
> I'll probably take some of these suggestions and use them to improve
> the code.

-- 
Michael Wood <esiot...@gmail.com>

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