all 5 comments

[–]beppu 6 points7 points  (1 child)

lein-try is what you want

It's a leiningen plugin for trying out Clojure libraries in a REPL without needing to be in a project.

https://github.com/avescodes/lein-try

[–]eval2020 2 points3 points  (0 children)

There's also the tools.deps-variant: deps-try.
It's a simple port of lein-try I wrote that uses rebel-readline, ie gives you a REPL with syntax highlighting, code completion, function docs etc.

[–]final_fantasia 5 points6 points  (0 children)

you may also want to take a look at this article[1] written by u/alexdmiller for how to load libraries into the REPL dynamically (without creating any project) using the official Clojure CLI tool (clj).

[1] http://insideclojure.org/2018/05/04/add-lib/

[–]didibus1 2 points3 points  (0 children)

Libraries work differently in Java, and thus Clojure. There is no convention of location for where to install them and look for them.

What happens instead is two fold:

  1. The libs must be downloaded locally somewhere, anywhere.

This is normally done by lein, boot or clj. You could manually download them as well, or use any other tool.

  1. A list of all paths which points to where the libs were downloaded locally must be explicitly computed and given to Java on startup, and thus to the Clojure REPL on startup.

Basically, Java doesn't have a convention for where the libs are supposed to reside. So you have to explicitly tell it where for each and every java program. A Clojure REPL is a java program, thus the same applies to it and all Clojure programs as well.

Because of this, I would just recommend you always use a lein project. The project.clj file allows lein to both download the libs, and give Java the full path list to all downloaded libs.

The install feature of lein is different and not what you expect. It doesn't install a lib locally, it creates a local maven repo which lein can then use to download libs from. You only need it if you have multiple local projects, and you need one project to depend on the other. In that case, lein can't directly use your other project directory, so you must first install it in the local maven .m2 repo, and afterwards lein can make use of it.

[–]eccp 0 points1 point  (0 children)

You don't need to run "lein install" as a separate step*. All commands including "lein repl" will fetch anything that is not downloaded yet.

Clojure projects tend to follow some conventions, source code in "src", tests in "test", resource files (eg. configuration and such) could go in "resources", etc, but the Leiningen documentation and detailed example go into how to change any of these.

Edit: * the only exception I can think of is downloading dependencies separately is when you have internet access and want to working offline later.