Publishing semantic-namespace/contract lib
Table of Contents
Today, I'm publishing semantic-namespace/contract a distilled design pattern of the semantic registry concepts I explored in my recent article "De-complecting clojure.spec".
This library provices a "semantic approach to clojure.core/def partially based on clojure.core.spec.alpha/def". In other words, it tries to fulfill the ideas included on clojure.spec guidelines: expressivity > proof
Below the text excerpt…. (the library semantic-namespace/contract only tries to help on the highlighted sentences):
Guidelines
expressivity > proof
There is no reason to limit our specifications to what we can prove, yet that is primarily what type systems do. There is so much more we want to communicate and verify about our systems. This goes beyond structural/representational types and tagging to predicates that e.g. narrow domains or detail relationships between inputs or between inputs and output. Additionally, the properties we care most about are often those of the runtime values, not some static notion. Thus spec is not a type system.
1. semantic-namespace/contract design
- Semantic ids/attributes are first-class - Individual fields (eg:
:docs/content
) have independent meaning (and optional spec viaclojure.spec
) - Contracts are collections of attributes - Contracts (eg:
:semantic-namespace/docs
) are just named collections of attributes that can be asserted about semantic subject identities - Instances accumulate assertions - Any instance/subject (identified by namespaced keyword) can have multiple contracts types associated, enabling information accretion without modification
- Context-independent semantics - The meaning of individual semantic ids/attributes (eg:
:docs/content
) remains stable regardless of which contract type includes it
2. Key Benefits
- Open-world assumption - New contracts can be defined without changing existing ones
- Reusable semantic fields - Attributes defined once, used across many contracts
- Discovery via contract-type registry - Can query which subjects/instances implement a contract
- Evolution without breakage - Following Rich Hickey's "accretion not breakage" principle
3. semantic-namespace playground
Also, I'm setting up semantic-namespace as a playground for experiments using semantic-namespaces, AKA clojure namespaced-keywords.
So far the semantic-namespace experiments are:
- semantic-namespace/contract: clojure.core/def partially based on clojure.core.spec.alpha/def
- semantic-namespace/contract.di: PoC component system dependency injection
- semantic-namespace/contract.function: PoC function interception (AOP related)
- semantic-namespace/contract.docs: documentation
- semantic-namespace/contract.iri: PoC RDF/IRIs representation