How do I start the REPL in a user defined namespace?

穿精又带淫゛_ 提交于 2019-11-28 00:55:20
BLUEPIXY
java -cp .;clojure-1.3.0.jar; clojure.main -e \
"(ns dbx) (clojure.main/repl) (in-ns 'dbx) (clojure.core/use 'clojure.core)"

Nowadays is :repl-options {:init-ns foo.bar}.

See https://github.com/technomancy/leiningen/blob/master/sample.project.clj

Abimaran Kugathasan

If you are using Leiningen to build your project, then add this to your project's project.clj file:

(defproject test "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.2.1"]]
  :main test.core)

In your src/test/core.clj file, add this to create a test.core namespace:

(ns test.core)

(defn -main [& args])

Next, build your project with Leiningen with lein compile. Then enter lein repl to invoke the REPL in your namespace. The REPL prompt will look like:

test.core=>
David J.

In addition to Carlos' answer suggesting :repl-options {:init-ns foo.bar}, I have also had success with adding :dev {:main user} to my profile.clj.

To give more context:

;; /foo/profile.clj
...
:main foo.core
:dev {:main user
      :source-paths ["dev"]}`
...

;; /foo/dev/user.clj
(ns user
  (:require
   [clojure.pprint :refer (pprint)]
   [clojure.repl :refer :all]
   [clojure.string :as str]
   [clojure.test :refer [run-tests run-all-tests]]
   [clojure.tools.namespace.repl :refer [refresh refresh-all]]))

Using tools.deps one way would be to define an alias and execute some forms in it:

:aliases
      {:cursive {:main-opts ["-e" "(load \"de/sveri/getless/user\")"
                             "-e" "(de.sveri.getless.user/reset)"]}

This will load the de.sveri.getless.user namespace and execute the de.sveri.getless.user.reset function afterwards.

(ns dbx) (clojure.main/repl) (in-ns 'dbx) (clojure.core/use 'clojure.core)

There is a much better way to do this in recent Clojure versions:

java -cp myapp.jar clojure.main -m myapp.core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!