Skip to content

Commit

Permalink
clojure: eval clojure with cider inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalli-johnny committed Jan 17, 2024
1 parent 8489373 commit 7ee5011
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions docs/evaluating-clojure/inspect.md
@@ -1,15 +1,27 @@
# Inspect Clojure values

`, d v` is the Cider Inspector menu used to efficiently page through large data sets and easily navigate through nested data structures.
`, d v` is the Cider Inspector menu used to efficiently page through very large data sets and navigate through nested data structures.

The Cider Inspector opens in a new buffer that shows the underlying type of the value and all of its details. of the current symbol under the cursor. This provides a very readable way to understand the value and browse through larger data sets.
`, d v l` shows the last evaluation in the inspector

The Cider Inspector is used in the [REPL driven development with Spacemacs video](https://youtu.be/NDrpclY54E0).
`, d v f` evaluates the top level expression under the cursor and displays the result in the inspector

`, d v e` evaluates the previous expression before the cursor and displays the result in the inspector

!!! HINT "Following evaluation results in Cider Inspector"
The Cider Inspector will show the results of any evaluation, from `, e` or `, d v` menus, whilst the buffer is visible.
Keep the Cider Inspector buffer open to update with the result of the latest expression evaluation, from `, e` or `, d v` menus.

??? INFO "Inspector in action"
Clojure REPL workflow video includes using the Cider Inspector, 20 minutes into the video

<p style="text-align:center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/NDrpclY54E0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</p>


## Use Inspector buffer

`, d v f` to evaluate a top level expression and show the results in the Cider Inspector.
Once Cider Inspector buffer is open:

`n` and `p` page through the data if the number of elements in the data set is greater than the page size (default 32), (`cider-inspector-next-page`, `cider-inspector-prev-page`)

Expand All @@ -26,6 +38,16 @@ The Cider Inspector is used in the [REPL driven development with Spacemacs video

## Inspecting simple values

Inspecting a dynamic var shows its value along with the datafy view

![Spacemacs Clojure Cider Inspector - OpenAPI docs example](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-dynamic-var-light.png?raw=true#only-light)
![Spacemacs Clojure Cider Inspector - OpenAPI docs example](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-dynamic-var-dark.png?raw=true#only-dark)

Inspect a system property shows

![Spacemacs Clojure Cider Inspector - OpenAPI docs example](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-system-property-light.png?raw=true#only-light)
![Spacemacs Clojure Cider Inspector - OpenAPI docs example](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-system-property-dark.png?raw=true#only-dark)

Inspecting a number or character shows the underlying type, the value and properties of that type

![Spacemacs - Clojure - Inspect value - java.lang.Long](/images/spacemace-clojure-inspect-java-lang-long.png)
Expand All @@ -35,34 +57,35 @@ Inspecting a number or character shows the underlying type, the value and proper

Inspect a collection shows the underlying type, contents of that collection and index (where applicable). Only the elements are shown. The characters of the overall collection itself are not show, only the underlying type of collection (vector, map, lazy sequence, etc.).

![Spacemacs - Clojure - Inspect persistent map](/images/spacemace-clojure-inspect-java-lang-persistentvector.png)
![Spacemacs - Clojure - Inspect persistent map](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-vector-light.png?raw=true#only-light)
![Spacemacs - Clojure - Inspect persistent map](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-vector-dark.png?raw=true#only-dark)

If there are collections within collections then those values can be navigated too.

`RET` on an nested element in a collection will inspect that element in the same detail (`cider-inspector-operate-on-point`).

![Spacemacs - Clojure - Inspect persistent map with vector](/images/spacemacs-clojure-inspect-persistent-map-nested.png)

`L` to back to parent of a nested element (`cider-inspector-pop`).


# Inspecting mutable values

Mutable containers, `atom`, `ref`, can also be inspected. The class of the container is shown, along with the class of the value it contains along with its elements.

![Spacemacs - Clojure - Inspect atom containing a vector](/images/spacemacs-clojure-inspect-atom-containing-persistent-vector.png)

Inspecting an atom or ref gives the value at the current time. The inspector does not update if the value of the atom or ref is updated. Use `r` in the inspector buffer to refresh or restart the inspector with `, d v` each time you want to check if the value has changed.


## Inspecting Var meta data

`cider-inspect-last-result` shows the result of the the last expression evaluated. When this is a var from a `def` expression then meta information is shown as well as the class type and summary of the value.
Inspecting a var from a `def` expression shows meta information, the class type and summary of the value. Meta data can include the file and position of the code, the name of the var and which namespace it is defined in.

Meta data includes the file and position of the code, the name of the var and which namespace it is defined in.

![Spacemacs Clojure Cider Inspector - inspect last value - def](/images/spacemacs-clojure-cider-inspect-last-result.png)
![Spacemacs Clojure Cider Inspector - inspect last value - def](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-var-def-light.png?raw=true#only-light)
![Spacemacs Clojure Cider Inspector - inspect last value - def](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-var-def-dark.png?raw=true#only-dark)

Inspecting a `defn` also shows the argument list as part of the meta data.

![Spacemacs Clojure Cider Inspector - inspect last value - defn](/images/spacemacs-clojure-cider-inspector-inspect-last-value-defn.png)
![Spacemacs Clojure Cider Inspector - inspect last value - defn](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-inspect-last-value-defn.png?raw=true)

Open API docs data structure example shows class, value, meta information and datafy data

![Spacemacs Clojure Cider Inspector - OpenAPI docs example](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-var-openapi-docs-light.png?raw=true#only-light)
![Spacemacs Clojure Cider Inspector - OpenAPI docs example](https://github.com/practicalli/graphic-design/blob/live/editors/spacemacs/screenshots/spacemacs-clojure-cider-inspector-var-openapi-docs-dark.png?raw=true#only-dark)

0 comments on commit 7ee5011

Please sign in to comment.