1.3.0 permalink Arrow_down_16x16

defstruct

clojure.core

  • (defstruct name & keys)
Same as (def name (create-struct keys...))

1 Example top

  • user=> (defstruct person :name :age :height)
    #'user/person
    
    user=> (struct person "george" 22 115)
    {:name "george", :age 22, :height 115}
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:3583 top

(defmacro defstruct
  "Same as (def name (create-struct keys...))"
  {:added "1.0"
   :static true}
  [name & keys]
  `(def ~name (create-struct ~@keys)))
Vars in clojure.core/defstruct:
Used in 0 other vars

Comments top

3 comment(s) for defstruct.

Structs are obsolete. Use records instead. See defrecord.

Are structs obsolete ? Or will become obsolete ? The docs for 'defrecord' have 'Alpha - Subject To Change' ?

The doc string for defrecord has been changed in Clojure 1.6 to remove the 'alpha' designation, along with many other Clojure functions: https://github.com/clojure/clojure/commit/93d13d0c0671130b329863570080c72799563ac7

Log in to add a comment.