-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
宏 视频课程 问题收集 #2
Comments
纠结应该使用宏还是函数 ;; 我有很多表在数据库里面
;; 他们有差不多的操作
;;
(defn create-fun-name [table-name op]
(symbol (str table-name "-" op)))
(defn deftable-op [table-name]
"将一样的操作抽象出来,比如: select all 和 delete id 等于 19 的记录"
(let [add-fun-name (create-fun-name table-name "select-all")
delete-fun-name (create-fun-name table-name "delete")]
(intern *ns* add-fun-name
(fn []
(str "select * from " table-name " where 1=1")))
(intern *ns* delete-fun-name
(fn [] (str "delete from " table-name " where id=19")))))
(comment
(deftable-op "foo")
;; => sample.core/foo-delete
(foo-select-all) ; 可以直接使用自动生成的函数, 下同
;; => "select * from foo where 1=1"
(foo-delete)
;; => delete from foo where id=19
(deftable-op "bar")
;; => sample.core/bar-delete
(bar-select-all)
;; => select * from bar where 1=1
(bar-delete)
;; => delete from bar where id=19
) ;; 宏代码 略 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: