(sc.api/spy) without a wrapped expressionThe key value proposition of scope-capture is not to record the values of an expression, but to recreate its local bindings.
For this reason, you can write (sc.api/spy) without wrapping an expression, which can be less intrusive.
Example:
(let [x (foo)
y (bar x)]
(sc.api/spy) ;; FIXME remove when done
(something-something x y))
(sc.api/spy) from inside a catch clause.Example:
(try
(my-fallible-code)
(catch Throwable err
(sc.api/spy err)
(throw err))
You might want to write a custom macro spy-on-err doing that:
(dev/spy-on-err
(my-fallible-code)
err)
You might want to create an editor shortcut for the following snippet
(eval `(sc.api/defsc ~(sc.api/last-ep-id)))
There is no built-in macro for that in the library, because it cannot work in standard ClojureScript environments.
For example, you could use defsc twice to combine values saved from different sites:
(defn my-fun-1 [a b]
(sc.api/spy) ;; saved a and b in EP [-1 3]
(something-about a b))
(defn my-fun-2 [x y]
(sc.api/spy) ;; saved x and y in EP [-2 4]
(something-about x y))
;; combining both scopes
(sc.api/defsc [-1 3])
(sc.api/defsc [-2 4])
(play-around-with a b x y)
spy and brk macros is allowed and encouragedPeople have vastly different tastes and opportunities regarding their programming experience, what and how notifications should be displayed, etc.
This is why scope-capture is designed to be customizable rather than opinionated on these aspects.
For simple cases where you just want to wrap a form with sc.api/spy, instead of writing
(require 'sc.api)
(sc.api/spy
(my-very interesting expression))
You can add a reader macro, and write it like this:
#sc/spy (my-very interesting expression)
To add such a reader macro defined in your own dev namespace, you would add
{sc/spy dev/read-sc-spy}
To data_readers.clj at a root of the classpath, as described in the clojure.core/*data-readers* docstring (you could use dev/data_readers.clj if dev is a source-path for your development environment), and define the reader macro in your dev namespace:
(defn read-sc-spy [form]
(require 'sc.api)
`(sc.api/spy ~form))
Since the reader macro itself requires the namespace, you can now simply add #sc/spy before the form you wish to capture in any namespace, evaluate it, and execute it.
NOTE: this tip will probably not work for ClojureScript.
Can you improve this documentation? These fine people already did:
Valentin Waeselynck & blak3mill3rEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |