Cyclic load dependency in Clojure

My project has a simple structure:

|- core.clj |- dialogs.clj |- dialogs/ |- name_dialog.clj 

name_dialog is dependent on core , and core is name_dialog .

So, I have dependencies like:

core.clj

 (ns ddsl.core (:gen-class) (:require [clojure.xml :refer :all] [ddsl.dialogs :refer :all])) 

dialogs.clj

 (ns ddsl.dialogs (:require [ddsl.core :refer :all])) (load "dialogs/name_dialog") 

name_dialog.clj

 (in-ns 'ddsl.dialogs) 

When I try to run the program, I get the following Cyclic load dependency: [ /ddsl/core ]->/ddsl/dialogs->[ /ddsl/core ] error Cyclic load dependency: [ /ddsl/core ]->/ddsl/dialogs->[ /ddsl/core ]

Please let me know how to restructure my project (I am new to Clojure).

+5
source share
1 answer

The classic answer, not specifically Clojure, might be to redefine the modules and their responsibilities.

( -> below means "depends on")

Given:

 core -> dialogs -> core 

Extract the part of the core module that the dialogs requires into a separate common module:

 shared (depends on "nothing") core -> dialogs -> shared core -> shared (possibly) 

As for me, cyclical dependencies are an indicator of something wrong with the design. Even when the technical problem is resolved (with a boot sequence or compilation, etc.), looping dependencies are usually a sign of hard communication and still deserve fixation.

+3
source

Source: https://habr.com/ru/post/1233154/


All Articles