Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one pre-load a clojure file in the leiningen repl?

I have some clojure functions that I would like pre-loaded when I start the clojure REPL. The functions aren't much use unless you are using them within the context of a REPL.

If it helps, I generally use leiningen to start a clojure REPL for me.

How can I tell clojure (or leiningen, if it's not available through flat clojure) to pre-load a clojure file containing these definitions for me?

like image 428
djhaskin987 Avatar asked Aug 31 '13 19:08

djhaskin987


People also ask

How do I start a REPL Clojure?

To start a REPL session in Eclipse, click the Menu option, go to Run As → Clojure Application. This will start a new REPL session in a separate window along with the console output.

What is Clojure REPL?

A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.

How do I get out of Clojure REPL?

You can exit the REPL by typing Ctrl+D (pressing the Ctrl and D keys at the same time).


1 Answers

There are several ways to do this described in the leiningen sample project one of my favorite methods is so put the code you want in the default repl namespace into

/path/to/project/dev/user.clj:

(ns user)
(def foo 42)

and add a line like this into the project.clj file:

(defproject hello "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]]
  :source-paths ["dev"])

This makes it clear that this is for dev while still getting it loaded into the default namespace.

When you run nrepl-jack-in form emacs or "lein repl" form the shell, you should be greeted with a user> namespace with your code loaded:

; nREPL 0.1.6
user> foo
42
like image 149
Arthur Ulfeldt Avatar answered Sep 28 '22 17:09

Arthur Ulfeldt