Namespace visibility and private var access constraints
24.5K reputation · 28 Sept 2021, 08:36 UTC
Clojure Var Visibility
Clojure provides a mechanism to mark vars as private by prefixing the symbol name with a colon during definition. This prevents the var from being exported in the namespace's var map, effectively blocking standard external access via namespace qualification.
While this approach manages public API surface area, it creates a binary visibility state. There is currently no native language-level configuration to implement a 'package-private' scope, where functions remain hidden from the global API but accessible to a specific group of related namespaces within the same directory or project module.
This lack of granular visibility can lead to architectural tension between maintaining strict encapsulation and avoiding the use of reflection or internal APIs for unit testing internal logic.
- What is the recommended pattern for achieving package-level visibility without exposing vars to the entire application?
- Are there documented configurations to allow specific namespaces to bypass private var restrictions for testing purposes?