### Tools to monkey-patch Clojure and Java code
(define-again namespaced-sym)
Refreshes a var by evaluating its source. Preserves metadata.
Refreshes a var by evaluating its source. Preserves metadata.
(java-patch & args)
Applies a monkey-patch to a java method.
mode
can be either :replace
, :before
or :after
.
body
can be javassist pseudo-java (a string) or clojure code.
In the latter case, args
must be specified before body
so as to
intercept the method's parameters. If :after
is used args
will
include the method's return value. If the method is an instance
method, args
will also include the instance it is called on
(this
).
args
: [this? return-value? & method-args]
(java-patch [clojure.lang.LispReader "read"
[java.io.PushbackReader "boolean" Object "boolean" Object]]
:replace
[reader eof-is-error eof-value _is-recursive opts]
(clojure.tools.reader/read
(merge {:eofthrow eof-is-error
:eof eof-value}
opts)
reader))
;; or
(java-patch [clojure.lang.LispReader$SyntaxQuoteReader "syntaxQuote"
[Object]]
:after
"{
$_ = clojure.lang.RT.list(
clojure.lang.Symbol.intern("clojure.core", "from-syntax-quote"),
$_
);
}")
Applies a monkey-patch to a java method. `mode` can be either `:replace`, `:before` or `:after`. `body` can be javassist pseudo-java (a string) or clojure code. In the latter case, `args` must be specified before `body` so as to intercept the method's parameters. If `:after` is used `args` will include the method's return value. If the method is an instance method, `args` will also include the instance it is called on (`this`). `args`: `[this? return-value? & method-args]` ```clojure (java-patch [clojure.lang.LispReader "read" [java.io.PushbackReader "boolean" Object "boolean" Object]] :replace [reader eof-is-error eof-value _is-recursive opts] (clojure.tools.reader/read (merge {:eofthrow eof-is-error :eof eof-value} opts) reader)) ;; or (java-patch [clojure.lang.LispReader$SyntaxQuoteReader "syntaxQuote" [Object]] :after "{ $_ = clojure.lang.RT.list( clojure.lang.Symbol.intern("clojure.core", "from-syntax-quote"), $_ ); }") ```
(monkey-patch name target args & body)
(monkey-patch perfid-incer clojure.core/+ [original & args]
(inc (apply original args)))
(+ 1 2)
=> 4
Supports reload. Name and target can be vars or symbols. Name can also be a keyword.
```clojure (monkey-patch perfid-incer clojure.core/+ [original & args] (inc (apply original args))) (+ 1 2) => 4 ``` Supports reload. Name and target can be vars or symbols. Name can also be a keyword.
(only name & body)
Ensures body
is executed only once with respect to name
.
If name
is a symbol or a keyword without a namespace, it will be
prefixed with the value of *ns*
.
(only 'foo (println "bar"))
; prints bar
(only 'foo (println "bar"))
; prints nothing
Ensures `body` is executed only once with respect to `name`. If `name` is a symbol or a keyword without a namespace, it will be prefixed with the value of `*ns*`. ```clojure (only 'foo (println "bar")) ; prints bar (only 'foo (println "bar")) ; prints nothing ```
(refresh-only name)
Reset only
statements by name. Next time one is called, the
associated code will be evaluated.
If name
is a symbol or a keyword without a namespace, it will be
prefixed with *ns*
.
(only 'foo (println "bar"))
; prints bar
(refresh-only 'foo)
(only 'foo (println "bar"))
; prints bar
Reset `only` statements by name. Next time one is called, the associated code will be evaluated. If `name` is a symbol or a keyword without a namespace, it will be prefixed with `*ns*`. ```clojure (only 'foo (println "bar")) ; prints bar (refresh-only 'foo) (only 'foo (println "bar")) ; prints bar ```
(require-from-dependent-namespaces requirement)
Requires a namespace from any namespace that has required it.
requirement
can be anything require
accepts.
(require-from-dependent-namespaces
'[clojure.core :refer [custom-fn]])
Requires a namespace from any namespace that has required it. `requirement` can be anything `require` accepts. ```clojure (require-from-dependent-namespaces '[clojure.core :refer [custom-fn]]) ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close