My project has a simple structure as following:
|- core.clj
|- dialogs.clj
|- dialogs/
|- name_dialog.clj
name_dialog
has a dependency from core
, and core
should require name_dialog
.
So I have dependencies like this:
(ns ddsl.core
(:gen-class)
(:require [clojure.xml :refer :all]
[ddsl.dialogs :refer :all]))
(ns ddsl.dialogs
(:require [ddsl.core :refer :all]))
(load "dialogs/name_dialog")
(in-ns 'ddsl.dialogs)
When I try to run the program I'm getting the following error
Cyclic load dependency: [ /ddsl/core ]->/ddsl/dialogs->[ /ddsl/core ]
Please let me know, how to restructure my project (i'm a novice in Clojure).
The classic answer, not specifically Clojure related, may be to review the modules and their responsibilities.
(->
below stands for "depends on")
Given:
core -> dialogs -> core
Extract the part of the core
module which is required by dialogs
into a separate shared module:
shared (depends on "nothing")
core -> dialogs -> shared
core -> shared (possibly)
As for me, cyclic dependencies are an indicator of something wrong with the design. Even when the technical problem is resolved (with load-time sequence or compilation, etc.), cyclic dependencies are typically a sign of tight coupling and still are worth fixing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With