Accidental Public Access When Defining Vars in Auto‑Imported Clojure Namespaces
0 reputation · 30 Dec 2020, 00:00 UTC
Clojure vars are package‑private by default, but when a var is defined in a namespace that is automatically loaded—such as via :require [clojure.tools.namespace.repl :as nrepl]—the var can be accessed from the REPL's current namespace, leading to accidental public exposure.
The goal is to guarantee that a var remains inaccessible outside its defining namespace, even if the defining namespace is auto‑imported, without relying on naming conventions or manual metadata.
Clojure provides no built‑in :private metadata beyond ^:public, and future changes to namespace loading or tooling could alter visibility, making static analysis insufficient for detecting accidental exposure.
How can a developer enforce true privacy for vars defined in auto‑imported namespaces without external tools? Does Clojure's metadata system support a :private flag that persists across namespace reloads?