Hi,
I think you have some misunderstandings here how things work.
* the # notation works only *inside* a syntax-quote.
* you have to create locals with # notation.
* var is a special form which looks up the Var named by the given
Symbol.
(defmacro create-database-methods
[table]
(let [kw-table (keyword table)]
`(do
(defn ~(symbol (str "drop-" table))
[]
(try
(drop-table ~kw-table)
(catch Exception _)))
(defn ~(symbol (str "insert-" table))
[data#]
(insert-value ~kw-table (keys data#) (vals data#)))
(defn ~(symbol (str "update-" table))
[id# attribute-map#]
(update-values ~kw-table ["id=?" id#] attribute-map#))
(defmacro ~'select-userentry
[id# & body#]
`(with-transaction
(with-query-results rs [~~(str "select * from " table
" where id=?") ~id#]
~...@body#))))))
Note: this will only work with a literal string as table argument!
(create-database-methods "table")
As a general advice: you are probably better of writing these as
functions
and then specialise them via currying.
(defn drop
[table]
(try
(drop-table table)
(catch Exception _)))
(defmacro create-database-methods
[table]
(let [kw-table (keyword table)]
`(do
(def ~(symbol (str "drop-" table)) (partial drop ~kw-table))
...)))
Hope this helps.
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en