State management and loosely coupled functions in Clojure

Web Technology   Digital Transformation Technology Artificial Intelligence Technology   Natural Language Processing Technology   Semantic Web Technology   Deep Learning Technology   Online Learning & Reinforcement Learning Technology  Chatbot and Q&A Technology   User Interface Technology   Knowledge Information Processing Technology   Reasoning Technology  Clojure Programming

When you try to introduce complex logic using state in Clojure, you may encounter cases where the tight coupling of functions and immutability, which are the features of Clojure, get in the way. For example, when considering a web-based backend application where the branch of the data to be routed changes according to the state of the history up to that point, if you try to build it with the usual ring + composure configuration, you will have to use the channels of core.async as I introduced before, or use the functions of atom and agent. If you want to build it with the usual ring + composure structure, you need to use channels of core.async as I introduced before, or use atom or agent, or use a library like pedestal to make the functions loosely coupled and mutable.

In the presentation by Rich Hickey, the author of Clojure, about core.async, he describes the weakness of Clojure as “Function chain make poor machine”. object and callback cases.

Rich Hickeyによるcore.asyncについて説明した資料よりJavaのようなオブジェクト型の場合

In the object type described above, logic and state become an integrated machine, which makes state management more complicated.

Rich Hickeyによるcore.asyncについて説明した資料よりCallBackやSTMを利用した場合

When the state is used outside the system (CallBack or STM), it becomes easier to manage the state. In contrast, Clojure’s Core.async looks like this

Clojureのcore.asyncでのケース

Instead of using the state associated with the logic (Direct), control is done by introducing queues (channels) before and after the logic (Indirect). The Direct structure is sufficient for simple control, but the Indirect method is more flexible and effective for complex pipelines that connect multiple logics.

In the next article, I would like to discuss some actual cases where these methods are used.

 

コメント

タイトルとURLをコピーしました