First values
You want a small vector and a map, their sizes, and a stable identity — without a file or a server. Build them as Dacite values. Count, get, and the content hash are the whole API you need here.
Five minutes. nbb only; no JVM.
Prerequisites
git clone https://github.com/jclaggett/dacite.git
cd dacite
npm install
Run the example
npm run hello
Expected shape of the output:
Dacite Hello World
vector count : 3
vector hash : 58a4799b…
map count : 2
map hash : 5de2bb0c…
(get m "hello") realized: 42
Done.
The exact hashes are stable across hosts (JVM, babashka, nbb) for the same value structure — that is part of the Dacite porting contract.
What the code does
Source: hello.cljc.
-
Create a mem store — an in-memory rooted store.
(def st (store/mem)) -
Build values — first argument is always a store, root, or peer value:
(def v (v/vector st 1 2 3)) (def m (v/map v "hello" (v/i64 v 42) "vec" v)) -
Read with
dacite.value— collection ops take the value first:(v/count v) ; => 3 (v/get m "hello") ; => Dacite scalar (v/realize …) ; => 42 -
Content hash — identity is the hash, independent of store location:
(store/hash->hex (v/hash v))
Try it in a one-liner
npx nbb -e "
(require '[dacite.store :as store]
'[dacite.value :as v])
(let [st (store/mem)
vec (v/vector st 1 2 3)]
(println (v/count vec))
(println (store/hash->hex (v/hash vec))))
"
Next steps
- Anatomy of a Dacite app — add a root and persist
- Persist and update a document — nested map, file or HTTP
- Values API — constructors, collection ops