<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged keywords</title>
<link>https://ask.clojure.org/index.php/tag/keywords</link>
<description></description>
<item>
<title>clojure.edn and clojure allows keywords with empty (&quot;&quot;) namespaces</title>
<link>https://ask.clojure.org/index.php/14811/clojure-edn-clojure-allows-keywords-with-empty-namespaces</link>
<description>&lt;p&gt;Following links and snippets are about clojure.edn but because this logic is the same in clojure it also affects clojure reader as well.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/EdnReader.java#L28&quot;&gt;Here&lt;/a&gt; is how symbol pattern is defined:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[:]?([\D&amp;amp;&amp;amp;[^/]].*/)?(/|[\D&amp;amp;&amp;amp;[^/]][^/]*)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is eagerly matching prefix until &lt;strong&gt;the last&lt;/strong&gt; slash character, after that it matches symbol name.&lt;/p&gt;
&lt;p&gt;Then &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/EdnReader.java#L289-L311&quot;&gt;there&lt;/a&gt; is a wrong analysis of matched groups happen: ns is incorrectly set to everything until the last slash with &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/EdnReader.java#L296&quot;&gt;validation&lt;/a&gt; that it is not ends with :/&lt;/p&gt;
&lt;p&gt;Then in Symbol.intern call there is an another lookup for &lt;strong&gt;the first&lt;/strong&gt; slash to split symbol into namespace and name.&lt;/p&gt;
&lt;p&gt;The result is that keywords like this: &quot;:/-/-&quot;, end up with namespace set to empty string &quot;&quot;.&lt;/p&gt;
&lt;p&gt;Looks like the least intrusive way to fix it is to use the same logic to find namespace borders in both places:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;during symbol reading, lookup the first / to set ns instead of using the first matching group&lt;/li&gt;
&lt;li&gt;in symbol interning the logic is correct&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another option is to use different regular expression: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[:]?([\D&amp;amp;&amp;amp;[^/]][^/]*/)?(/|[\D&amp;amp;&amp;amp;[^/]].*[^/])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This matches symbol prefix til &lt;strong&gt;the first&lt;/strong&gt; slash keeping restriction &quot;name can't end with slash&quot;.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14811/clojure-edn-clojure-allows-keywords-with-empty-namespaces</guid>
<pubDate>Fri, 05 Dec 2025 09:56:54 +0000</pubDate>
</item>
<item>
<title>Keyword internal cache cleaning logic approach</title>
<link>https://ask.clojure.org/index.php/13027/keyword-internal-cache-cleaning-logic-approach</link>
<description>&lt;p&gt;just want to clarify my understanding of that &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Keyword.java#L39&quot;&gt;code&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;	Reference&amp;lt;Keyword&amp;gt; existingRef = table.get(sym);
if(existingRef == null) // keyword was not found
	{
	Util.clearCache(rq, table);  // force cleaning of the dead weak references in the whole cache

           ....create new keyword and store it wrapped into WeakReference in the cache
	}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Maybe i am missing something but what are the reasons/assumptions to force cache clearing from dead weak references on every cache miss if rq is not empty, i.e. there is seq scan of the whole cache to locate dead references and to remove them.&lt;br&gt;
And seq scan is executed during Keyword function calling, i.e. blocks the caller.&lt;/p&gt;
&lt;p&gt;Naive alternative is to dedicate a thread which collects the garbage from the cache with a some period (~10 seconds or smth like that)&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13027/keyword-internal-cache-cleaning-logic-approach</guid>
<pubDate>Wed, 21 Jun 2023 11:27:05 +0000</pubDate>
</item>
<item>
<title>Could some calls to clojure.core/= be replaced by clojure.core/identical?</title>
<link>https://ask.clojure.org/index.php/12721/could-some-calls-clojure-core-replaced-clojure-core-identical</link>
<description>&lt;p&gt;I'm using &lt;code&gt;core.cache&lt;/code&gt; in combination with &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/raxod502/lazy-map&quot;&gt;&lt;code&gt;LazyMap&lt;/code&gt;&lt;/a&gt;. Lazy maps are map-like objects (new data type encapsulating maps and adding some logic to auto-force delayed values associated with keys).&lt;/p&gt;
&lt;p&gt;When I started putting lazy maps as values of FIFO Cache I observed that all values are being realized just after the map lands in cache. After some digging I've found that it is caused by expression &lt;code&gt;(= ::expired v)&lt;/code&gt; in &lt;code&gt;clojure.core.cache.wrapped/lookup-or-miss&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What happens is that &lt;code&gt;=&lt;/code&gt; internally calls &lt;code&gt;clojure.lang.Util/equiv&lt;/code&gt; (since &lt;code&gt;LazyMap&lt;/code&gt; implements &lt;code&gt;IPersistentCollection&lt;/code&gt;) and then, after some dispatching, &lt;code&gt;equiv&lt;/code&gt; is called to check whether the contents of a lazy map equals to other object (implicitly other map). This is the desired behavior and lazy map realizes all values to make comparison possible.&lt;/p&gt;
&lt;p&gt;However, when comparing a map-like object to something which is not a map (nor a collection), short-circuit would be welcome as soon as we know that it will for sure return &lt;code&gt;false&lt;/code&gt;. But changing that is probably more related to Clojure itself and things like &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-1375&quot;&gt;CLJ-1375&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What could be done on &lt;code&gt;core.cache&lt;/code&gt;'s side, if that's not too problematic, would be a replacement of&lt;/p&gt;
&lt;p&gt; &lt;code&gt;(= ::expired v)&lt;/code&gt; with &lt;code&gt;(identical? ::expired v)&lt;/code&gt;   &lt;/p&gt;
&lt;p&gt;in &lt;code&gt;clojure.core.cache.wrapped&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It would not only fix corner cases like mine but also speed things up a bit (explicit referential equality rocks when it comes to Clojure keywords).&lt;/p&gt;
&lt;p&gt;Other expressions where that could be changed (just in case) are:&lt;br&gt;
 &lt;code&gt;(= ::nope ret)&lt;/code&gt; and &lt;code&gt;(= ::nil v)&lt;/code&gt; from &lt;code&gt;clojure.core.cache&lt;/code&gt;.&lt;/p&gt;
</description>
<category>core.cache</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12721/could-some-calls-clojure-core-replaced-clojure-core-identical</guid>
<pubDate>Thu, 02 Mar 2023 22:47:18 +0000</pubDate>
</item>
<item>
<title>The `keyword` and `symbol` docstrings don't mention that using `&quot;a/b&quot;` as its only argument is valid</title>
<link>https://ask.clojure.org/index.php/12657/keyword-symbol-docstrings-mention-that-using-argument-valid</link>
<description>&lt;p&gt;The current docstrings:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure.core/keyword
([name] [ns name])
  Returns a Keyword with the given namespace and name.  Do not use :
  in the keyword strings, it will be added automatically.

clojure.core/symbol
([name] [ns name])
  Returns a Symbol with the given namespace and name. Arity-1 works
  on strings, keywords, and vars.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The arglists suggest that the first arity is to be used for simple idents only.&lt;br&gt;
However, the underlying implementation explicitly handles the case when there's &lt;code&gt;/&lt;/code&gt; in the value, and even the argument is named &lt;code&gt;nsname&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static public Symbol intern(String nsname){
	int i = nsname.indexOf('/');
	if(i == -1 || nsname.equals(&quot;/&quot;))
		return new Symbol(null, nsname);
	else
		return new Symbol(nsname.substring(0, i), nsname.substring(i + 1));
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One example where some existing code relies on this behavior: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/cognitect/transit-clj/blob/972759aed878d354fbd65de3e4525345955e86b4/src/cognitect/transit.clj#L205-L207&quot;&gt;transit-clj&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Perhaps, the docstrings should be updated to reflect that?&lt;/p&gt;
</description>
<category>Docs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12657/keyword-symbol-docstrings-mention-that-using-argument-valid</guid>
<pubDate>Wed, 08 Feb 2023 16:53:38 +0000</pubDate>
</item>
<item>
<title>Shouldn't Keyword extend AFn like Symbol?</title>
<link>https://ask.clojure.org/index.php/12468/shouldnt-keyword-extend-afn-like-symbol</link>
<description>&lt;p&gt;In source code I have noticed that Keyword class doesn't extend AFn and there are a lot of &lt;code&gt;invoke&lt;/code&gt; declarations, which can be removed by extending AFn. And for that purpose AFn, I suppose, exists.&lt;/p&gt;
&lt;p&gt;So why Keyword doesn't extend AFn? And comparing with Symbol behaviour, shouldn't it be considering as a bug?&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;br&gt;
(instance? clojure.lang.AFn :asdf)&lt;br&gt;
=&amp;gt; false&lt;/p&gt;
&lt;p&gt;(instance? clojure.lang.AFn 'asdf)&lt;br&gt;
=&amp;gt; true&lt;br&gt;
&lt;code&gt;`&lt;/code&gt; &lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12468/shouldnt-keyword-extend-afn-like-symbol</guid>
<pubDate>Sun, 11 Dec 2022 08:59:35 +0000</pubDate>
</item>
<item>
<title>Add function that returns every interned keyword in the runtime</title>
<link>https://ask.clojure.org/index.php/12171/add-function-that-returns-every-interned-keyword-the-runtime</link>
<description>&lt;p&gt;Having access to a list of every interned keyword in the runtime is useful for implementing editor auto-completion and other editor integration features.&lt;/p&gt;
&lt;p&gt;Currently, most tooling does something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user=&amp;gt; (let [field (.getDeclaredField clojure.lang.Keyword &quot;table&quot;)] (.setAccessible field true) (map keyword (.keySet (.get field nil))))
(:target :clojure.main/message :clojure.spec.alpha/unknown :datafy :clojure.core.specs.alpha/prefix :dir :clojure.core.specs.alpha/binding-form :allow ...)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, this approach relies on reflection to grab hold of a private, static field. The underlying bits are presumably (albeit unlikely) subject to change without notice.&lt;/p&gt;
&lt;p&gt;Would it be possible to add a function into clojure.core that returns a list of all keywords in the runtime? Perhaps &lt;code&gt;(all-keywords)&lt;/code&gt; (like &lt;code&gt;(all-ns)&lt;/code&gt;). Or perhaps a public static method to &lt;code&gt;clojure.lang.Keyword&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;See also &lt;a rel=&quot;nofollow&quot; href=&quot;https://grep.app/search?q=.getDeclaredField%20clojure.lang.Keyword%20%22table%22&quot;&gt;grep.app&lt;/a&gt; results for this pattern.&lt;/p&gt;
</description>
<category>REPL</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12171/add-function-that-returns-every-interned-keyword-the-runtime</guid>
<pubDate>Wed, 07 Sep 2022 18:18:21 +0000</pubDate>
</item>
<item>
<title>Error when deserializing a keyword after upgrading from Clojure 1.10.3 to 1.11.0 (java.io.InvalidClassException)</title>
<link>https://ask.clojure.org/index.php/11699/deserializing-upgrading-clojure-invalidclassexception</link>
<description>&lt;p&gt;I have recently updated our application from Clojure 1.10.3 to 1.11.0 and we are now facing deserilization issues when reading an object serialized by the former version via Quartz (scheduler).&lt;/p&gt;
&lt;p&gt;This is the error we are getting: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;....
org.quartz.impl.StdScheduler.getJobDetail StdScheduler.java: 498
org.quartz.core.QuartzScheduler.getJobDetail QuartzScheduler.java: 1518
org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob JobStoreSupport.java: 1374
org.quartz.impl.jdbcjobstore.JobStoreSupport.executeWithoutLock JobStoreSupport.java: 3739
org.quartz.impl.jdbcjobstore.JobStoreTX.executeInLock JobStoreTX.java: 93
org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock JobStoreSupport.java: 3803
org.quartz.impl.jdbcjobstore.JobStoreSupport$9.execute JobStoreSupport.java: 1377
org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob JobStoreSupport.java: 1385
org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectJobDetail StdJDBCDelegate.java: 860
org.quartz.impl.jdbcjobstore.StdJDBCDelegate.getObjectFromBlob StdJDBCDelegate.java: 3201
java.io.ObjectInputStream.readObject ObjectInputStream.java: 460
...
java.io.ObjectStreamClass.initNonProxy ObjectStreamClass.java: 699
java.io.InvalidClassException: clojure.lang.Keyword; local class incompatible: stream classdesc serialVersionUID = -2105088845257724163, local class serialVersionUID = 2404715664513862299
org.quartz.JobPersistenceException: Couldn't retrieve job because the BLOB couldn't be deserialized: clojure.lang.Keyword; local class incompatible: stream classdesc serialVersionUID = -2105088845257724163, local class serialVersionUID = 2404715664513862299
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I'm wondering if the problem is that Keyword.java has &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/commit/bd4c42dc7946cb015b8d0699596662aa68bcdc89&quot;&gt;changed recently&lt;/a&gt;&lt;br&gt;
and because it doesn't declare it's own &lt;em&gt;serialVersionUID&lt;/em&gt; it got a new one.&lt;br&gt;
Is there any reason why the Keyword class doesn't declare its own serialVersionUID? Can we get it fixed?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11699/deserializing-upgrading-clojure-invalidclassexception</guid>
<pubDate>Tue, 29 Mar 2022 15:04:10 +0000</pubDate>
</item>
<item>
<title>clj-uuid/v5 uuids inconsistent after Clojure 1.11.0</title>
<link>https://ask.clojure.org/index.php/11658/clj-uuid-v5-uuids-inconsistent-after-clojure-1-11-0</link>
<description>&lt;p&gt;Hi, i’ve come across the following when updating to Clojure 1.11.0. In our application we have some places where we create V5 (name based, SHA1 hash) uuids, using the danlentz/clj-uuid library. After the upgrade the v5 uuid’s produced are different. An example being:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def ^:const +namespace+ #uuid &quot;50d94d91-a1cf-422d-9586-4ddacf6df176&quot;)

(clj-uuid/v5 +namespace+ :some-keyword) 

;; Clojure 1.10.3
=&amp;gt; #uuid &quot;d30e9c3c-ced2-534e-a6b8-ecf784fb0785&quot;

;; Clojure 1.11.0
=&amp;gt; #uuid &quot;a16f6719-952a-55b9-b71b-b15dd263665b&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After some trial an error It seems it is the local part argument i.e :some-keyword that is causing the difference, as within the clj-uuid/v5 fn it converts the keyword Object to a ByteArray, which now appears to be different. (If I use a String instead of a keyword for the local part argument then the uuid produced is consistent before and after the Clojure upgrade.)&lt;br&gt;
The uuids produced are used in downstream systems and It would be quite difficult to have them handle the change. Is there anyway that I could achieve the exact same previous uuids?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11658/clj-uuid-v5-uuids-inconsistent-after-clojure-1-11-0</guid>
<pubDate>Wed, 23 Mar 2022 14:21:43 +0000</pubDate>
</item>
<item>
<title>When to use simple/qualified keywords?</title>
<link>https://ask.clojure.org/index.php/10380/when-to-use-simple-qualified-keywords</link>
<description>&lt;p&gt;Is there any &quot;official&quot; guidance on this?&lt;/p&gt;
&lt;p&gt;Clojure.spec uses both:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/def ::foo (s/keys :req [::bar]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The current usecase I'm wondering about is an internal API I'm working on. It is pretty clear that top-level keys in the api response benefit from being qualified. How about keywords in value positions?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:my.api.person/name &quot;Imre&quot;
 :my.api/result-type :success ;; :my.api.result/success perhaps?
 :my.api/warnings [:quota-exceeded :my.api.quota/exceeded]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Edit: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurians-log.clojureverse.org/clojure/2021-03-26/1616759029.465400&quot;&gt;Slack discussion where I brought this up first&lt;/a&gt;&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10380/when-to-use-simple-qualified-keywords</guid>
<pubDate>Fri, 26 Mar 2021 13:47:38 +0000</pubDate>
</item>
<item>
<title>defrecord qualified field names</title>
<link>https://ask.clojure.org/index.php/10160/defrecord-qualified-field-names</link>
<description>&lt;p&gt;Coming from a RDF background I tend to use qualified keywords a lot when defining properties. However after looking at the &lt;a rel=&quot;nofollow&quot; href=&quot;https://cljdoc.org/d/metosin/reitit/0.5.12/doc/introduction&quot;&gt;Reitit&lt;/a&gt; HTTP router it appears that &lt;code&gt;defrecord&lt;/code&gt; is really benefitial for performance. This often leads me to a choice between performance or clean data representation when designing software.&lt;/p&gt;
&lt;p&gt;In order to avoid this dilemma, I think it would be nice if &lt;code&gt;defrecord&lt;/code&gt; could support something similar to what is already done for map destructuring&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def m {:domain/id 14 :other/id &quot;UV&quot;})

(let [{:keys [domain/id]} m] id)
;;; ⤷ 14
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We could have something like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defrecord Employee [domain/id domain/full-name]
  Object
  (toString [_]
    (str &quot;&amp;lt;&amp;lt; id: &quot; id &quot;, name: &quot; full-name &quot; &amp;gt;&amp;gt;&quot;)))

(def alyssa (-&amp;gt;Employee 14 &quot;Alyssa P. Hacker&quot;))

(.toString alyssa)
;;; ⤷ &quot;&amp;lt;&amp;lt; id: 14, name: Alyssa P. Hacker &amp;gt;&amp;gt;&quot;

(:domain/id alyssa)
;;; ⤷ 14
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the name part is bound in the record definition and is used as the Java internal class field&lt;/li&gt;
&lt;li&gt;the fully qualified  identifier is used when accessing/manipulating the record objects from its map-like interface.&lt;/li&gt;
&lt;li&gt;collision in the field names would throw&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I have implemented &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/mthl/qrecord&quot;&gt;a prototype&lt;/a&gt; to demonstrate how it could be done in practice. I wonder if such extension has already been considered for &lt;code&gt;clojure.core/defrecord&lt;/code&gt; and if there are some design/implementation issues that I am overlooking.&lt;/p&gt;
</description>
<category>Records and Types</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10160/defrecord-qualified-field-names</guid>
<pubDate>Sat, 06 Feb 2021 21:17:36 +0000</pubDate>
</item>
<item>
<title>Listing all keywords in a namespace</title>
<link>https://ask.clojure.org/index.php/10044/listing-all-keywords-in-a-namespace</link>
<description>&lt;p&gt;In clojure, symbols can optionally belong to a namespace:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:FileType/TXT
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is it possible to list all keywords that are defined for a given keyword namespace?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10044/listing-all-keywords-in-a-namespace</guid>
<pubDate>Wed, 13 Jan 2021 17:04:23 +0000</pubDate>
</item>
<item>
<title>is there a version of pr-str that emit full versions of qualified keywords in maps instead of short forms?</title>
<link>https://ask.clojure.org/index.php/9222/there-version-versions-qualified-keywords-instead-short-forms</link>
<description>&lt;p&gt; Something like &lt;code&gt;{:foo/bar 1}&lt;/code&gt; instead of &lt;code&gt;#:foo{:bar 1}&lt;/code&gt;&lt;br&gt;
I need to debug some edn and it's impossible to jump to the desired keywords if they're in the short forms.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9222/there-version-versions-qualified-keywords-instead-short-forms</guid>
<pubDate>Fri, 10 Apr 2020 07:54:25 +0000</pubDate>
</item>
<item>
<title>What is keywords for clj used for? What do they actually mean and do?</title>
<link>https://ask.clojure.org/index.php/9192/what-is-keywords-for-clj-used-for-what-they-actually-mean-and</link>
<description>&lt;p&gt;I learned about keywords a while back, but Im not sure what they are actually used for outside of for keys in maps. Are there other uses for keywords outside of maps?&lt;/p&gt;
&lt;p&gt;Also what do they actually mean and do?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9192/what-is-keywords-for-clj-used-for-what-they-actually-mean-and</guid>
<pubDate>Fri, 27 Mar 2020 09:04:53 +0000</pubDate>
</item>
<item>
<title>How to read namespaced keywords with clojure.tools.reader/read?</title>
<link>https://ask.clojure.org/index.php/8856/how-read-namespaced-keywords-with-clojure-tools-reader-read</link>
<description>&lt;p&gt;I'm using clojure.tools.reader/read for reading clojure and cljs  forms from files.&lt;/p&gt;
&lt;p&gt;Everything works fine but reading namespaced keywords like &lt;code&gt;::keyword&lt;/code&gt; get read as :user/keyword. &lt;/p&gt;
&lt;p&gt;I know the reader uses &lt;em&gt;ns&lt;/em&gt; dynamic var to figure out the current namespace for reading symbols and keywords but I don't know how to use it to read a non existing namespace, like the one from the file I'm just reading.&lt;/p&gt;
&lt;p&gt;I'm trying a (in-ns file-ns-symbol) before doing the read so it creates the ns before reading and it works but sometimes I'm getting &lt;code&gt;java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Just doing &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(binding [*ns* file-ns-symbol]
  (reader/read ...))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;doesn't work since it will try to call (the-ns file-ns-symbol) for a ns that doesn't exist.&lt;/p&gt;
&lt;p&gt;Any ideas or pointers on how to do this?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description>
<category>tools.reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8856/how-read-namespaced-keywords-with-clojure-tools-reader-read</guid>
<pubDate>Mon, 18 Nov 2019 14:04:04 +0000</pubDate>
</item>
<item>
<title>Transducers and Maps</title>
<link>https://ask.clojure.org/index.php/8654/transducers-and-maps</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I'm learning more about transducers, but coming up with some deadends. &lt;/p&gt;
&lt;p&gt;What I'm looking to understand, is whether they are appropriate to use (in my use-case, but also as a learning exercise) and whether what I am doing is right/efficient/maybe-there-is-a-better-way :-)&lt;/p&gt;
&lt;p&gt;Let' say I have a data stucture thus:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; (def trip {:tripData 
            {:segments [{:dataPoints 
                         [{:location {:lat 1 :lng 2}} 
                          {:location {:lat 3 :lng 4}}]}]}})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There could be hundreds/thousands of dataPoints with each dataPoint having a single location.&lt;/p&gt;
&lt;p&gt;I want to efficiently extract out only the lat and lng into a single collection and turn it into a string. I came up with this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; (def xf
   (comp
    (mapcat :dataPoints)
    (map :location)
    (map (fn [{lat :lat lng :lng}] (str lat &quot; &quot; lng)))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then evaluated via:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def lat-lng (into [] xf (-&amp;gt;&amp;gt; trip :tripData :segments)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I get back something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[&quot;1 2&quot; &quot;3 4&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which I can then do (for the purposes of my exercise), this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; (clojure.string/join &quot;, &quot; lat-lng)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to obtain, finally, this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&quot;1 2, 3 4&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which is all fine and dandy :-)&lt;/p&gt;
&lt;p&gt;However, given my inexperience with transducers, I'm left wondering if there is a different/better way. For example, a way, within the comp xf, to turn the data into the string and joined at the end instead of using clojure.string/join.&lt;/p&gt;
&lt;p&gt;I also discovered, I can do this too, without the use of transducers:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; (def lat-lng-2 (-&amp;gt;&amp;gt; trip
                     :tripData
                     :segments
                     (mapcat :dataPoints)
                     (map :location)
                     (map (fn [{lat :lat lng :lng}] (str lat &quot; &quot; lng)))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which, given the clojure.string/join, ends up with the same result.&lt;/p&gt;
&lt;p&gt;However, it's my understanding that you can't use a map keyword (i.e., :tripData, :segments) as part of a comp as keywords are not transducers.&lt;/p&gt;
&lt;p&gt;I'm at a loss on how to make this efficent/better whilst learning how I can use transducers.&lt;/p&gt;
&lt;p&gt;I would appreciate some help/guidance/feedback!&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
</description>
<category>Transducers</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8654/transducers-and-maps</guid>
<pubDate>Tue, 24 Sep 2019 20:14:24 +0000</pubDate>
</item>
</channel>
</rss>