Is where a canonical doc about ~' or I have to read the core.clj? On 8月21日, 下午10时40分, Nicolas Oury <nicolas.o...@gmail.com> wrote: > Clojure whitin a `(...) context resolves the name space of symbols. > This is most often what you want and prevent some name collisions at > macro expension. > > But as binders can not be name-space resolved this do not allow to write: > > `(let [and ....]) > > this would expand to (let [ns/and ...]) which is forbidden. > > The usual solutions (choose the first applicable) : > > - use automatic name generation > `(let [and# ....] and#) > > - generate a symbol name: > (let [my-fresh-sym (gensym "foo_")] > `(let [~my-fresh-sym ...]) > > It is mostly useful when the same symbols occurs in a complex > structure of `(...)s. > > - If you really need to choose the name a binding symbol: use ~'symbol. > This says to the evaluation of `() "replace by exactly symbol" > So > (`let [~'and ...]) will expand to (let [and ...] ) this is a problem > because it can conflict with some other names. > However, in some case it is very useful/necessary. Especially when you > want to expose some symbols to the macro user. > > > > > > > > On Sat, Aug 21, 2010 at 3:20 PM, limux <liumengji...@gmail.com> wrote: > > This is some code in a blog of William Gropper, the useage of ~'= > > confused me, waiting some more detailed explain, advanced thanks > > > (defmacro filter > > [pred query] > > `(let [~'and (fn[& xs#] (apply str (interpose " AND " xs#))) > > ~'or (fn[& xs#] (apply str (interpose " OR " xs#))) > > ~'= (fn[x# y#] (sql-exp "=" x# y#)) > > ~'> (fn[x# y#] (sql-exp ">" x# y#)) > > ~'< (fn[x# y#] (sql-exp "<" x# y#)) > > ~'like (fn[x# y#] (sql-exp "like" x# y#)) > > ~'in (fn[x# xs#] > > (str (sqlize x#) " IN (" (apply str (interpose ", " xs#)) ")"))] > > (apply str ~query " where " ~pred))) > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/clojure?hl=en
-- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en