accessor

clojure.core

  • (accessor s key)
Returns a fn that, given an instance of a structmap with the basis,
returns the value at the key. The key must be in the basis. The
returned function should be (slightly) more efficient than using
get, but such use of accessors should be limited to known
performance-critical areas.

1 Example top

  • (defstruct car-struct :make :model :year :color)
    
    (def car (struct car-struct "Toyota" "Prius" 2010))
    
    (def make (accessor car-struct :make))
    
    user=> (make car)  ; Same as both (car :make) and (:make car)
    "Toyota"           
    
    
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:3609 top

(defn accessor
  "Returns a fn that, given an instance of a structmap with the basis,
  returns the value at the key.  The key must be in the basis. The
  returned function should be (slightly) more efficient than using
  get, but such use of accessors should be limited to known
  performance-critical areas."
  {:added "1.0"
   :static true}
  [s key]
    (. clojure.lang.PersistentStructMap (getAccessor s key)))
Vars in clojure.core/accessor:
Used in 0 other vars

Comments top

No comments for accessor. Log in to add a comment.