Created
September 11, 2011 01:50
-
-
Save halcat0x15a/1209066 to your computer and use it in GitHub Desktop.
夜中のテンションで超便利とか思ってたけど実際作ったらそんなに便利でもなかったマクロ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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