Skip to content

Instantly share code, notes, and snippets.

@halcat0x15a
Created September 11, 2011 01:50
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 halcat0x15a/1209066 to your computer and use it in GitHub Desktop.
Save halcat0x15a/1209066 to your computer and use it in GitHub Desktop.
夜中のテンションで超便利とか思ってたけど実際作ったらそんなに便利でもなかったマクロ
(use '[clojure.string :only (join split capitalize)])
(defn split-hyphen [string]
(split string #"\-"))
(defn upper-camel [string]
(join (map capitalize (split-hyphen string))))
(defn lower-camel [string]
(let [strings (split-hyphen string)]
(join (cons (first strings) (map capitalize (rest strings))))))
(defmacro x [class constructor methods]
`(doto (new ~class ~@constructor)
~@(map #(let [[method# value#] %] `(. ~(symbol (lower-camel (str (if (empty? value#) "" "set-") (subs (str method#) 1)))) ~@value#)) methods)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment