Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns hiredman.beans)
(defn -it [& _]
[[] (ref {})])
(defn setter [tis nam tat]
(dosync
(commute (.state tis)
assoc nam tat)))
(defn getter [tis nam]
(@(.state tis) nam))
(defn up-first-letter [x]
(str (.toUpperCase (subs x 0 1)) (subs x 1 (count x))))
(defmacro acessors [names]
(let [n names]
`(do ~@(map (fn [nam]
`(do (defn- ~(symbol (str "-get" (up-first-letter (name nam)))) [tis#]
(getter tis# ~nam))
(defn- ~(symbol (str "-set" (up-first-letter (name nam)))) [tis# tat#]
(setter tis# ~nam tat#))))
n))))
(defmacro mk-bean [nam & props]
`(do
(gen-class :name ~nam
:init ~(symbol "it")
:methods ~(loop [p props out []]
(if p
(recur (rest p)
(conj out
[(symbol (str "set" (up-first-letter (name (first p))))) [Object] 'void]
[(symbol (str "get" (up-first-letter (name (first p))))) [] Object]))
out))
:state ~(symbol "state"))
(acessors ~props)))
(mk-bean hiredman.wsbean :fid :fname :father :mother :streat :city :state :zip :phone1 :phone2 :femail :aid :anme :dob :gender :grade :aemail :aim :app_date)
;; user=> (show (hiredman.wsbean.))
;; === hiredman.wsbean ===
;; [ 0] ()
;; [ 1] state : class java.lang.Object
;; [ 2] clone : class java.lang.Object (0)
;; [ 3] equals : boolean (1)
;; [ 4] getAemail : class java.lang.Object (0)
;; [ 5] getAid : class java.lang.Object (0)
;; [ 6] getAim : class java.lang.Object (0)
;; [ 7] getAnme : class java.lang.Object (0)
;; [ 8] getApp_date : class java.lang.Object (0)
;; [ 9] getCity : class java.lang.Object (0)
;; [10] getClass : class java.lang.Class (0)
;; [11] getDob : class java.lang.Object (0)
;; [12] getFather : class java.lang.Object (0)
;; [13] getFemail : class java.lang.Object (0)
;; [14] getFid : class java.lang.Object (0)
;; [15] getFname : class java.lang.Object (0)
;; [16] getGender : class java.lang.Object (0)
;; [17] getGrade : class java.lang.Object (0)
;; [18] getMother : class java.lang.Object (0)
;; [19] getPhone1 : class java.lang.Object (0)
;; [20] getPhone2 : class java.lang.Object (0)
;; [21] getState : class java.lang.Object (0)
;; [22] getStreat : class java.lang.Object (0)
;; [23] getZip : class java.lang.Object (0)
;; [24] hashCode : int (0)
;; [25] notify : void (0)
;; [26] notifyAll : void (0)
;; [27] setAemail : void (1)
;; [28] setAid : void (1)
;; [29] setAim : void (1)
;; [30] setAnme : void (1)
;; [31] setApp_date : void (1)
;; [32] setCity : void (1)
;; [33] setDob : void (1)
;; [34] setFather : void (1)
;; [35] setFemail : void (1)
;; [36] setFid : void (1)
;; [37] setFname : void (1)
;; [38] setGender : void (1)
;; [39] setGrade : void (1)
;; [40] setMother : void (1)
;; [41] setPhone1 : void (1)
;; [42] setPhone2 : void (1)
;; [43] setState : void (1)
;; [44] setStreat : void (1)
;; [45] setZip : void (1)
;; [46] toString : class java.lang.String (0)
;; [47] wait : void (0)
;; [48] wait : void (1)
;; [49] wait : void (2)
;; nil
;; user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.