<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged state</title>
<link>https://ask.clojure.org/index.php/tag/state</link>
<description></description>
<item>
<title>Why vswap is a macro instead of function like swap?</title>
<link>https://ask.clojure.org/index.php/14531/why-vswap-is-a-macro-instead-of-function-like-swap</link>
<description>&lt;p&gt;Why &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2556C17&quot;&gt;clojure.core/vswap&lt;/a&gt; is a macro with tag hint instead of a function called on clojure.lang.Volatile similar to &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2362&quot;&gt;clojure.core/swap&lt;/a&gt;?&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14531/why-vswap-is-a-macro-instead-of-function-like-swap</guid>
<pubDate>Sun, 04 May 2025 21:16:23 +0000</pubDate>
</item>
<item>
<title>What's an ideomatic way to manage state in a library?</title>
<link>https://ask.clojure.org/index.php/13734/whats-an-ideomatic-way-to-manage-state-in-a-library</link>
<description>&lt;p&gt;I’m porting a JS library to clojure (and, potentially cljs), and I’m struggling with reasoning about local state. Imagine a scenario where you do RPC over websockets, and the server reply contextually depend on what the server had already sent you. You'd want to keep a local cache of the replies from the server, then.&lt;/p&gt;
&lt;p&gt;In OOP world it's expected you incapsulate both the socket and the cache and provide the library users an interface that sends RPCs and transparently handles the cache population and pulling results from it. What would be the ideomatic way to do the same in clojure[-script]? Would I just return a map and expect my functions to take it as a first argument, returning the update state along with the rpc result?&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13734/whats-an-ideomatic-way-to-manage-state-in-a-library</guid>
<pubDate>Thu, 15 Feb 2024 12:46:36 +0000</pubDate>
</item>
<item>
<title>Using the state instantiated by integrant init-key</title>
<link>https://ask.clojure.org/index.php/13447/using-the-state-instantiated-by-integrant-init-key</link>
<description>&lt;p&gt;hi folks, I am trying out Integrant library for state management. It's quite intuitive when it comes to managing (starting/halting) servers but I am confused regarding a certain use case. &lt;/p&gt;
&lt;p&gt;I want to use integrant to instantiate and destroy an object. As usual I defined defmethods &lt;code&gt;init-key&lt;/code&gt;  and &lt;code&gt;halt-key!&lt;/code&gt; . The problem is that I want a reference to the initialised object from init-key . Is there an idiomatic way to do this? Should I just have it available in an atom  during init-key ?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defmethod ig/init-key :my-space/my-key [_ opts]
  (let [account-id (:account-id opts)
        license-key (:license-key opts)]
    (MyObject. account-id license-key)))

;;How do I use the instantiated my object?
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Libs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13447/using-the-state-instantiated-by-integrant-init-key</guid>
<pubDate>Fri, 10 Nov 2023 07:09:07 +0000</pubDate>
</item>
</channel>
</rss>