(rontolisp) docs
← Reference

clojure.datafy

Values turned into data, and navigation from data back to what it stands for, over the protocols of clojure.core.protocols. Require clojure.datafy to use it; clojure.core.protocols is loaded before the program, as in Clojure, so a qualified name reaches it without a require. Both are Clojure source written for rontolisp from the documented behavior of Clojure's namespaces, and run the same on every backend.

VarBehavior
clojure.datafy/datafy(datafy x): x as data through Datafiable; when that answers a new collection, its metadata holds x as :clojure.datafy/obj and the symbol of its class as :clojure.datafy/class. An exception answers Throwable->map's map; an atom, ref or agent [value] with its metadata
clojure.datafy/nav(nav coll k v): what v, found under k in coll, stands for, through Navigable; v itself unless extended
clojure.core.protocols/Datafiable, datafyThe protocol behind datafy: nil and every other value answer themselves; extendable through metadata
clojure.core.protocols/Navigable, navThe protocol behind nav, extendable through metadata
clojure.core.protocols/CollReduce, coll-reduce(coll-reduce coll f) / (coll-reduce coll f val): reduce of a collection by the collection itself. A record, deftype or reify extending it reduces through it under reduce, into, transduce and the other verbs built on reduce (reduce)
clojure.core.protocols/IKVReduce, kv-reduce(kv-reduce amap f init): reduce-kv of a collection by the collection itself, which reduce-kv, update-vals and update-keys reach for a record, deftype or reify extending it
clojure.core.protocols/InternalReduce, internal-reduce(internal-reduce s f start): reduce of a seq as a protocol

A protocol declared extendable through metadata finds a method in the value's metadata under the method's qualified symbol, ahead of the extensions:

A type reduces through its own CollReduce or IKVReduce row:

Differences

  • iterator-reduce! is not built in (it reduces a java.util.Iterator); naming it is an error that says so.
  • reduce and reduce-kv consult CollReduce and IKVReduce for a record, deftype or reify only: an extension of either protocol to nil, Object or a core kind (a String, a map) is reached by calling coll-reduce or kv-reduce itself, while Clojure's reduce takes it for a collection that does not reduce itself (a string, a map). reduce does not consult InternalReduce.
  • A namespace or class datafies to itself (Clojure answers a map of its members). An exception's map has no frames (Throwable->map).