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: examples/dacite/examples/hello.cljs.
-
Create a mem store — an in-memory
hash → nodedictionary.(def st (store/mem-store)) -
Build values — bootstrap with an explicit store, then
*-viafor peers:(def v (v/vector-with-store st 1 2 3)) (def m (v/hash-map-via v "hello" (v/i64-via 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/dacite-hash v))
Try it in a one-liner
npx nbb -e "
(require '[dacite.store :as store]
'[dacite.value :as v])
(let [st (store/mem-store)
vec (v/vector-with-store st 1 2 3)]
(println (v/count vec))
(println (store/hash->hex (v/dacite-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,
*-via, collection ops