I think this cache is just the same with String.intern method in java,it just want to reduce the cost (memory & cpu) of producing keywords frequently especial when using them with map structure.
2012/7/18 jaime <xiejianm...@gmail.com> > I doubt because keyword will use its internal Symbol object to compare > with each other (or other objects), it means it's Symbol's interned > strings(ns & name) make the comparison fast but not this caching stuff. I > found a "find()" method in source code but not sure if the cache is > relevant to this method..... > > 在 2012年7月18日星期三UTC+8下午4时52分25秒,dennis写道: > >> Compare keywords can be very fast. >> 在 2012-7-18 PM4:51,"jaime" <xiejianm...@gmail.com>写道: >> >>> Hello, >>> >>> When I read the source code keyword, say, Keyword.java (V1.3), I found >>> that when we "intern" a keyword, (if I understand it correctly) it uses >>> a cache for keywords: >>> ==============================**=============== >>> public static Keyword intern(Symbol sym) { >>> if (sym.meta() != null) >>> sym = (Symbol) sym.withMeta(null); >>> *Util.clearCache(rq, table);* >>> Keyword k = new Keyword(sym); >>> Reference<Keyword> existingRef = table.putIfAbsent(sym, >>> new WeakReference<Keyword>(k, rq)); >>> if (existingRef == null) >>> return k; >>> Keyword existingk = existingRef.get(); >>> if (existingk != null) >>> return existingk; >>> // entry died in the interim, do over >>> table.remove(sym, existingRef); >>> return intern(sym); >>> } >>> ==============================**================ >>> >>> well, I just don't understand why we need caching for keywords. Anyone >>> could give me a hint? >>> >>> -- >>> 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+unsubscribe@**googlegroups.com<clojure%2bunsubscr...@googlegroups.com> >>> For more options, visit this group at >>> http://groups.google.com/**group/clojure?hl=en<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 > -- 庄晓丹 Email: killme2...@gmail.com xzhu...@avos.com Site: http://fnil.net Twitter: @killme2008 -- 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