<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged namespace</title>
<link>https://ask.clojure.org/index.php/tag/namespace</link>
<description></description>
<item>
<title>Can: &quot;Alias already exists in namespace&quot; be fixed?</title>
<link>https://ask.clojure.org/index.php/12235/can-alias-already-exists-in-namespace-be-fixed</link>
<description>&lt;p&gt;When defining a namespace alias in an &lt;code&gt;ns&lt;/code&gt; form, and then later changing the namespace that alias refers to, you get an error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns foo.bar
  (:require [my.xxx :as xxx]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I evaluate this in my REPL. Later I change it to:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns foo.bar
  (:require [other.xxx :as xxx]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I get this exception&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;java.lang.IllegalStateException
Alias xxx already exists in namespace foo.bar, aliasing my.xxx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's a pretty gnarly sharp edge. Many people won't find a better solution than restarting their REPLs. Experienced Clojure developers will tell you to do&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns-unalias *ns* 'xxx)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and re-evaluate the ns form, but that's a pretty silly workaround. The right thing to do would be to drop the old alias and pick up the new one.&lt;/p&gt;
&lt;p&gt;You'd (I supposed) still have to re-evaluate the code that uses the alias before it gets picked up, but that's fairly consistent with Clojure's mental model IMO.&lt;/p&gt;
&lt;p&gt;We can redefine vars, why can't we redefine namespace aliases?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12235/can-alias-already-exists-in-namespace-be-fixed</guid>
<pubDate>Mon, 26 Sep 2022 13:51:27 +0000</pubDate>
</item>
<item>
<title>How can I have a clj REPL namespace be the same as the namespace defined in my file.clj?</title>
<link>https://ask.clojure.org/index.php/11441/how-have-repl-namespace-the-same-the-namespace-defined-file</link>
<description>&lt;p&gt;I am using Emacs/Cider to launch a &lt;code&gt;clj&lt;/code&gt; REPL. I do this by first opening my file which defines a new namespace. I then use &lt;code&gt;cider-jack-in-clj&lt;/code&gt; to launch the REPL. The REPL namespace is “user”. I can only use fully qualified functions within the REPL. If I enter &lt;code&gt;user=&amp;gt; (ns myns)&lt;/code&gt; in the REPL, this works and changes the namespace as expected. I would like to automate this so that every time I launch a REPL from a file the REPL namespace changes as well.&lt;/p&gt;
&lt;p&gt;Alternatively, I am ok not changing the namespace as long as I can use unqualified functions.&lt;/p&gt;
&lt;p&gt;Here is an example from the top of my file, core.clj&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns coresync.core
(:use [tupelo.core])
(:require [clojure.core.async :refer [chan &amp;gt;!! &amp;lt;!!]]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within the emacs buffer for the code, I am able to get all the unqualified functions, but within the REPL, I need to use:&lt;/p&gt;
&lt;p&gt; &lt;code&gt;user=&amp;gt; clojure.core.async/chan&lt;/code&gt; &lt;/p&gt;
&lt;p&gt;I’ve searched online and through this forum, but I haven’t been able to figure this out. I’m sorry in advance if this has already been asked and I missed it.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>Namespaces and vars</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11441/how-have-repl-namespace-the-same-the-namespace-defined-file</guid>
<pubDate>Fri, 07 Jan 2022 18:47:07 +0000</pubDate>
</item>
<item>
<title>json writer and namespaces</title>
<link>https://ask.clojure.org/index.php/9758/json-writer-and-namespaces</link>
<description>&lt;p&gt;Hello &lt;/p&gt;
&lt;p&gt;I'm new to Clojure and didn't find answer so please sorry if this is not issue at all. &lt;/p&gt;
&lt;p&gt;lets say we have data: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:space1/value 123 :space2/value 456}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and use &lt;code&gt;clojure.data.json&lt;/code&gt; as serialiser: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(clojure.data.json/write-str {:space1/value 123 :space2/value 456})
=&amp;gt; &quot;{\&quot;value\&quot;:123,\&quot;value\&quot;:456}&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you see result is not what one can expect.&lt;br&gt;
Obvious solution would be to provide own &lt;code&gt;key-fn&lt;/code&gt; and forget about it. But I spend a lot of time catching bug caused by default implementation and like to save time of other &lt;/p&gt;
</description>
<category>data.json</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9758/json-writer-and-namespaces</guid>
<pubDate>Thu, 05 Nov 2020 11:50:53 +0000</pubDate>
</item>
</channel>
</rss>