Skip to content

Commit

Permalink
add-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
puredanger committed Dec 18, 2023
1 parent e73a79b commit 3a239a8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions content/reference/repl_and_main.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,25 @@ By default, the Clojure REPL starts in the `user` namespace and this namespace i
The Clojure REPL automatically loads the following namespaces and refers the following functions:

* `clojure.repl` - https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/source[`source`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/apropos[`apropos`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/dir[`dir`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/pst[`pst`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/doc[`doc`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/find-doc[`find-doc`]
* `clojure.repl.deps` - https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-lib[`add-lib`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-libs[`add-libs`] https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/sync-deps[`sync-deps`]
* `clojure.java.javadoc` - https://clojure.github.io/clojure/clojure.java.javadoc-api.html#clojure.java.javadoc/javadoc[`javadoc`]
* `clojure.pprint` - https://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/pp[`pp`] https://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/pprint[`pprint`]

If you switch to a different namespace (with `in-ns` or `ns`), these functions will not be available unless referred there explicitly.

Also, the Clojure runtime will look for and load the `user` namespace on startup if it is found. Generally, this should only be used to provide development-time faciliities, and not in a production scenario.

[[add-lib]]
== Adding libraries for interactive use

The <<xref/../../../guides/install_clojure#,Clojure CLI>> can be used to <<deps_edn#,declare dependencies>> loaded at REPL startup time. Since Clojure 1.12, you can also dynamically load libraries at the REPL for interactive use. These functions are available in the `tools.deps.repl` namespace:

* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-lib[`add-lib`] takes a lib that is not available on the classpath, and makes it available by downloading (if necessary) and adding to the classloader. Libs already on the classpath are not updated. If the coordinate is not provided, the newest Maven or git (if the library has an inferred git repo name) version or tag are used.
* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-libs[`add-libs`] is like `add-lib`, but resolves a set of new libraries and versions together.
* https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/sync-deps[`sync-deps`] calls `add-libs` with any libs present in <<deps_edn#,deps.edn>>, but not yet present on the classpath.

These new functions are intended only for interactive use at the repl - using a deps.edn etc is still the proper way to build and maintain your code. To this end, these functions all check that `pass:[*repl*]` is bound to `true`. In a clojure.main REPL, these new functions are automatically referred in the user namespace. In other repls, you may need to `(require '[clojure.repl.deps :refer :all])` before use.

== tap

tap is a shared, globally accessible system for distributing a series of informational or diagnostic values to a set of (presumably effectful) handler functions. It can be used as a better debug `prn`, or for facilities like logging etc.
Expand Down

0 comments on commit 3a239a8

Please sign in to comment.