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

前端 未结 7 1356
傲寒
傲寒 2020-12-06 17:13

Writing (in-ns \'dbx) to a file and loading it isn\'t changing the default namespace of the repl (using cygwin/console). The namespace is still user=><

相关标签:
7条回答
  • 2020-12-06 17:42

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

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

    0 讨论(0)
  • 2020-12-06 17:46

    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]]))
    
    0 讨论(0)
  • 2020-12-06 17:51

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

    0 讨论(0)
  • 2020-12-06 18:02

    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=>
    
    0 讨论(0)
  • 2020-12-06 18:03
    java -cp .;clojure-1.3.0.jar; clojure.main -e \
    "(ns dbx) (clojure.main/repl) (in-ns 'dbx) (clojure.core/use 'clojure.core)"
    
    0 讨论(0)
  • 2020-12-06 18:05

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

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

    0 讨论(0)
提交回复
热议问题