clerk icon indicating copy to clipboard operation
clerk copied to clipboard

dependency resolution in case of double defined defs is non-deterministic

Open behrica opened this issue 3 years ago • 1 comments

Code such as

(def a 1)
...
...
(def a 2)
(+ a 1)

in an notebook results sometimes in 2 , sometimes in 3

behrica avatar Jan 30 '22 20:01 behrica

Code like thgis coukld detect such as situation:

(def parsed
  (clerk/parse-file "notebooks/duplicate.clj"))


(def analyzed
  (h/build-graph parsed))

(def duplicate-vars
  (->> analyzed :doc :blocks (map :var) frequencies (filter (fn [[key val]] (>  val 1))) keys vec))

I propose to run such a detection during analysis, and fail on it for now, saying:

"Clerk's dependency analysis and caching cannot handle redefined vars"
The following vars are redefined ....

Having this in a namespace can result in un-noticeable and hard to debug issues.

behrica avatar Feb 21 '22 09:02 behrica