create-struct creates an anonymous Clojure struct definition from a set of keys. The definition can then produce ordered, map-like instances with struct or struct-map. section 11.1.4
Listing 11.4. → Constrained Map, Guarded keys
(create-struct [& keys]) (defstruct [name & keys]) (struct-map [s & inits]) (struct [s & vals]) (accessor [s key])
The compact API listing shows how create-struct relates to defstruct, struct-map, struct, and accessor. section 11.1.4
Key behavior:
- Requires at least one key and returns a PersistentStructMap$Def definition object. section 11.1.4
- Pass the definition and positional values to struct; missing values become nil, while excess values throw IllegalArgumentException. section 11.1.4
- Use struct-map for key-value initialization; defined keys default to nil, and additional keys are accepted. section 11.1.4
Parsing positional data
(let [sdef (create-struct :type :lat :lon :id)] (apply struct sdef ["VHF" "0.000000" "0.000000" "ABI"])) ;; {:type "VHF", :lat "0.000000", :lon "0.000000", :id "ABI"}
