Loading a .clj file automatically at repl startup?

185 views
Skip to first unread message

Mike K

unread,
Dec 28, 2009, 6:16:23 PM12/28/09
to Clojure
Is it possible to load a library such as foo.clj (with (ns foo ...) at
the top of the file) into the repl automatically at startup, rather
than having to (use 'foo) every time the repl starts? I'd like to
avoid creating a .jar file.

If possible, I'd like to do this both from the command line ("java -
cp ...") and from within slime / emacs.

Thanks,
Mike

Sean Devlin

unread,
Dec 28, 2009, 7:01:13 PM12/28/09
to Clojure
There's a user.clj file that can be customized for this purpose. Make
sure it's in your classpath.

Tom Hicks

unread,
Dec 28, 2009, 8:34:00 PM12/28/09
to Clojure
Depending how you're starting the REPL, it looks like there is also
a command line option. Here's parts of the doc string from the main fn
in src/clj/clojure/main.clj (version 1.0.0):

(defn main
"Usage: java -cp clojure.jar clojure.main [init-opt*] [main-opt]
[arg*]

With no options or args, runs an interactive Read-Eval-Print Loop

init options:
-i, --init path Load a file or resource
-e, --eval string Evaluate expressions in string; print non-nil
values

...[snip]....

- Runs all init options in order
- Runs a repl or script if requested

The init options may be repeated and mixed freely, but must appear
before
any main option. The appearance of any eval option before running a
repl
suppresses the usual repl greeting message: \"Clojure ~(clojure-
version)\".
"

Caveat: I haven't actually tried this.
-tom

Joost

unread,
Dec 29, 2009, 2:26:11 AM12/29/09
to Clojure
You can also create a small start.clj file that does whatever it needs
to do (use 'foo) and ends with a call to (clojure.main/repl)

Reply all
Reply to author
Forward
0 new messages