Skip to content

Instantly share code, notes, and snippets.

@hnaohiro
Created December 3, 2013 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnaohiro/7769002 to your computer and use it in GitHub Desktop.
Save hnaohiro/7769002 to your computer and use it in GitHub Desktop.
Clojure word count
(ns wordcount.core
(:gen-class)
(:use [seesaw core graphics]))
(defn text-area []
(scrollable
(text :id :txt :multi-line? true :font "MONOSPACED-PLAIN-14")))
(defn count-char [txt]
(count (re-seq #"\S" txt)))
(defn text-count [e]
(alert
(count-char (text (select (to-frame e) [:#txt])))))
(defn text-clear [e]
(text! (select (to-frame e) [:#txt]) ""))
(defn button-area []
(flow-panel
:align :center
:hgap 5
:items [(button :text "count" :listen [:action text-count])
(button :text "clear" :listen [:action text-clear])]))
(defn -main [& args]
(let [f (frame :title "word count"
:on-close :exit
:size [600 :by 400]
:content (border-panel :center (text-area)
:south (button-area)
:vgap 5 :hgap 5 :border 10))]
(invoke-later (-> f show!))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment