Liking cljdoc? Tell your friends :D

par

Clojars Project

A Clojure(Script) library designed to print-and-return values. Designed to wrap existing forms in your source code so they can be observed without changing the execution of the program. Whether you are logging to a browser console from ClojureScript or a terminal console from Clojure, printed values will have similar (if not identical) formatting.

The screen recordings below show the editor (left), and Chrome DevTools Console (right).




Example below demonstrates passing a comment to display (instead of the form being evaluated).



Example below demonstrates passing a comment and the keyword :form to display both the comment and the form being evaluated.

Usage

Add as a dependency to your project:

[org.clojars.paintparty/par "2.0.0"]

Import into your namespace:

(ns myns.core
  (:require
    [par.core :refer [? !? ?j !?j]]))

?

Use the par.core/? macro to print the form and resulting value. You should expect the same console output whether you are using Clojure or ClojureScript:

(? (+ 1 2))

The example above would print the following:

(+ 1 2) => 3

If you would like to add some commentary to your logs:

(? "Note to self" (+ 1 2))

The above will prepend the first argument to the output.
The form that is being evaluated will not be printed.
The example above would print the following:

Note to self => 3

If you would like both the commentary and form to be printed:

(?+ "Note to self" :form (+ 1 2))

The example above would print the following:

Note to self
(+ 1 2) => 3

?j

par.core/?jis designed to be used when you want to use js/console.log under the hood in order to leverage binaryage/cljs-devtools. Make sure that you have "Enable custom formatters" checked in Chrome's Developer Tools. This can be found in Chrome via View > Developer > Developer Tools, and then click on the settings gear at the top of the Dev Tools panel. The "Enable custom formatters" toggle is in the Console section.


!? and !?j

par.core/!? and par.core/!?j are both no-op macros, useful when you want to temporarily silence the printing on a form that is already wrapped by ? or ?j.


Roadmap

  • Create companion production stub (no-op) library to include for prod builds (Feb '23).
  • Incorporate a custom pretty-printer (Apr '23)

License

Copyright © 2020-2023 Jeremiah Coyle

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close