struct-map

clojure.core

  • (struct-map s & inits)
Returns a new structmap instance with the keys of the
structure-basis. keyvals may contain all, some or none of the basis
keys - where values are not supplied they will default to nil.
keyvals can also contain keys not in the basis.

1 Example top

  • ;; create a new struct type
    (defstruct s :1 :2)
    #'user/s
    
    user=> (type s)
    clojure.lang.PersistentStructMap$Def
    
    ;; create an instance of this new struct type
    (def s1 (struct s "one" "two"))
    #'user/s1
    
    user=> (println s1)
    {:1 "one", :2 "two"}
    
    user=> (type s1)
    clojure.lang.PersistentStructMap
    
    ;; create a new struct instance that is based on the previous struct type
    ;; with the option of supplying a new key/value pairs
    (def s2 (struct-map s :3 "three"))
    #'user/s2
    
    user=> (println s2)
    {:1 nil, :2 nil, :3 "three"}
    
    user=> (type s2)
    clojure.lang.PersistentStructMap
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3590 top

(defn struct-map
  "Returns a new structmap instance with the keys of the
  structure-basis. keyvals may contain all, some or none of the basis
  keys - where values are not supplied they will default to nil.
  keyvals can also contain keys not in the basis."
  {:added "1.0"
   :static true}
  [s & inits]
    (. clojure.lang.PersistentStructMap (create s inits)))
Vars in clojure.core/struct-map:
Used in 0 other vars

Comments top

No comments for struct-map. Log in to add a comment.