You're viewing version 1.2.0 of update-proxy. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

update-proxy

clojure.core

  • (update-proxy proxy mappings)
Takes a proxy instance and a map of strings (which must
correspond to methods of the proxy superclass/superinterfaces) to
fns (which must take arguments matching the corresponding method,
plus an additional (explicit) first arg corresponding to this, and
updates (via assoc) the proxy's fn map. nil can be passed instead of
a fn, in which case the corresponding method will revert to the
default behavior. Note that this function can be used to update the
behavior of an existing instance without changing its identity.

1 Example top

  • ;; from http://groups.google.com/group/clojure/msg/71702435ccd1d189
    user> (import java.util.Date)
    java.util.Date
    
    user> (def d (proxy [Date] [] (toString [] "hello")))
    #'user/d
    
    user> d
    #<Date$0 hello>
    
    user> (.toString d)
    "hello"
    
    user> (.toGMTString d)
    "17 Nov 2010 12:57:28 GMT"
    
    user> (update-proxy d {"toGMTString" (fn [this] "goodbye")})
    nil
    
    user> (.toGMTString d)
    "goodbye" 
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core_proxy.clj:281 top

(defn update-proxy
  "Takes a proxy instance and a map of strings (which must
  correspond to methods of the proxy superclass/superinterfaces) to
  fns (which must take arguments matching the corresponding method,
  plus an additional (explicit) first arg corresponding to this, and
  updates (via assoc) the proxy's fn map. nil can be passed instead of
  a fn, in which case the corresponding method will revert to the
  default behavior. Note that this function can be used to update the
  behavior of an existing instance without changing its identity."
  {:added "1.0"}
  [^IProxy proxy mappings]
    (. proxy (__updateClojureFnMappings mappings)))
Vars in clojure.core/update-proxy: defn proxy
Used in 1 other vars proxy-call-with-super

Comments top

No comments for update-proxy. Log in to add a comment.