带有 boot-clj 和 Emacs 的 Clojure - 最小应用程序

Clojure with boot-clj and Emacs - minimal application

如何使用 boot-clj 和 Emacs 获得 运行 最小的 Clojure 应用程序?

我安装了 Boot 应用程序和 运行 boot -h 两次。然后我得到了这个

s@Lux:~$ boot -V
#http://boot-clj.com
#Mon Feb 04 00:23:28 CET 2019
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.8.0
BOOT_VERSION=2.8.2
s@Lux:~$ 

我的Emacs版本如下

GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-09-15, modified by Debian

我安装了 ciderclojure-modeprojectile

我用这个 https://github.com/boot-clj/boot/wiki/Cider-REPL#a-better-way 的教程配置了 Emacs 并得到一个配置文件:

s@Lux:~$ cat ~/.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
(package-initialize)

(custom-set-variables
 '(cider-boot-parameters (quote "cider repl -s wait"))
 '(package-selected-packages (quote (projectile clojure-mode-extra-font-locking cider))))
s@Lux:~$

然后我输入了这个 C-x C-f ~/Dropbox/Clojure/myapp2/src/myapp2/core.clj

文件打开。

这是文件的代码:

s@Lux:~$ cat ~/Dropbox/Clojure/myapp2/src/myapp2/core.clj
(ns myapp2.core
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))
s@Lux:~$ 

该文件位于由 boot-clj 命令生成的项目中 boot -d boot/new new -t app -n myapp2

然后我输入这个 M-x cider-jack-in 并得到一个错误:

    line: 1

error in process sentinel: Could not start nREPL server: Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.10.0
Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.10.0
Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.10.0
                                       java.lang.Thread.run              Thread.java:  748
         java.util.concurrent.ThreadPoolExecutor$Worker.run  ThreadPoolExecutor.java:  624
          java.util.concurrent.ThreadPoolExecutor.runWorker  ThreadPoolExecutor.java: 1149
                        java.util.concurrent.FutureTask.run          FutureTask.java:  266
                                                        ...                               
                        clojure.core/binding-conveyor-fn/fn                 core.clj: 1938
                                          boot.core/boot/fn                 core.clj: 1032
                                        boot.core/run-tasks                 core.clj: 1022
                             boot.task.built-in/fn/fn/fn/fn             built_in.clj:  492
                                         clojure.core/deref                 core.clj: 2228
                                                        ...                               
                                boot.task.built-in/fn/fn/fn             built_in.clj:  489
                                         clojure.core/apply                 core.clj:  646
                                                        ...                               
                                     boot.core/launch-nrepl                 core.clj: 1313
                                     boot.repl/launch-nrepl                 repl.clj:   60
                              boot.repl-server/start-server          repl_server.clj:   68
                                 boot.repl-server/->mw-list          repl_server.clj:   59
                                                        ...                               
                                        clojure.core/mapcat                 core.clj: 2674 (repeats 2 times)
                                         clojure.core/apply                 core.clj:  646
                                                        ...                               
                                        clojure.core/map/fn                 core.clj: 2644
                                 boot.repl-server/->mw-list          repl_server.clj:   55
                                     boot.repl-server/->var          repl_server.clj:   49
                                                        ...                               
                                       clojure.core/require                 core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                     clojure.core/load-libs                 core.clj: 5758
                                     clojure.core/load-libs                 core.clj: 5774
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                      clojure.core/load-lib                 core.clj: 5717
                                      clojure.core/load-lib                 core.clj: 5736
                                   clojure.core/load-lib/fn                 core.clj: 5737
                                      clojure.core/load-one                 core.clj: 5697
                                                        ...                               
                                          clojure.core/load                 core.clj: 5876
                                          clojure.core/load                 core.clj: 5892
                                       clojure.core/load/fn                 core.clj: 5893
                                                        ...                               
                         refactor-nrepl.middleware/eval2021           middleware.clj:    1
         refactor-nrepl.middleware/eval2021/loading--auto--           middleware.clj:    1
                                                        ...                               
                                       clojure.core/require                 core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                     clojure.core/load-libs                 core.clj: 5758
                                     clojure.core/load-libs                 core.clj: 5774
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                      clojure.core/load-lib                 core.clj: 5717
                                      clojure.core/load-lib                 core.clj: 5736
                                   clojure.core/load-lib/fn                 core.clj: 5737
                                      clojure.core/load-one                 core.clj: 5697
                                                        ...                               
                                          clojure.core/load                 core.clj: 5876
                                          clojure.core/load                 core.clj: 5892
                                       clojure.core/load/fn                 core.clj: 5893
                                                        ...                               
                refactor-nrepl.ns.resolve-missing/eval14613      resolve_missing.clj:    1
refactor-nrepl.ns.resolve-missing/eval14613/loading--auto--      resolve_missing.clj:    1
                                                        ...                               
                                       clojure.core/require                 core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                     clojure.core/load-libs                 core.clj: 5758
                                     clojure.core/load-libs                 core.clj: 5774
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                      clojure.core/load-lib                 core.clj: 5717
                                      clojure.core/load-lib                 core.clj: 5755
                                         clojure.core/apply                 core.clj:  648
                                                        ...                               
                                         clojure.core/refer                 core.clj: 4087
                                         clojure.core/refer                 core.clj: 4119
java.lang.IllegalAccessError: info-clj does not exist
  clojure.lang.ExceptionInfo: info-clj does not exist
    line: 1

但是当我删除

 '(cider-boot-parameters (quote "cider repl -s wait"))

从配置行,重启Emacs,运行cider-jack-in,cider启动成功。所以我可以 运行 Clojure 命令,例如 (range 5)

但是,当我尝试 运行 应用程序并推出 (-main) 时,它崩溃了,并提示发生错误并且 main 符号无法解析:

user> (-main)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: -main in this context, compiling:(*cider-repl Clojure/myapp2:localhost:45545(clj)*:43:7) 
user> 

  Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (24 frames hidden)

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling *cider-repl Clojure/myapp2:localhost:45545(clj)* at (43:7)

             Compiler.java: 6688  clojure.lang.Compiler/analyze
             Compiler.java: 6625  clojure.lang.Compiler/analyze
             Compiler.java: 3766  clojure.lang.Compiler$InvokeExpr/parse
             Compiler.java: 6870  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6669  clojure.lang.Compiler/analyze
             Compiler.java: 6625  clojure.lang.Compiler/analyze
             Compiler.java: 6001  clojure.lang.Compiler$BodyExpr$Parser/parse
             Compiler.java: 5380  clojure.lang.Compiler$FnMethod/parse
             Compiler.java: 3972  clojure.lang.Compiler$FnExpr/parse
             Compiler.java: 6866  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6669  clojure.lang.Compiler/analyze
             Compiler.java: 6924  clojure.lang.Compiler/eval
             Compiler.java: 6890  clojure.lang.Compiler/eval
                  core.clj: 3105  clojure.core/eval
                  core.clj: 3101  clojure.core/eval
                  main.clj:  240  clojure.main/repl/read-eval-print/fn
                  main.clj:  240  clojure.main/repl/read-eval-print
                  main.clj:  258  clojure.main/repl/fn
                  main.clj:  258  clojure.main/repl
                  main.clj:  174  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   83  nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  646  clojure.core/apply
                  core.clj: 1881  clojure.core/with-bindings*
                  core.clj: 1881  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   81  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   50  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  221  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  189  nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1149  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  624  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  748  java.lang.Thread/run

1. Caused by java.lang.RuntimeException
   Unable to resolve symbol: -main in this context

                 Util.java:  221  clojure.lang.Util/runtimeException
             Compiler.java: 7164  clojure.lang.Compiler/resolveIn
             Compiler.java: 7108  clojure.lang.Compiler/resolve
             Compiler.java: 7069  clojure.lang.Compiler/analyzeSymbol
             Compiler.java: 6648  clojure.lang.Compiler/analyze
             Compiler.java: 6625  clojure.lang.Compiler/analyze
             Compiler.java: 3766  clojure.lang.Compiler$InvokeExpr/parse
             Compiler.java: 6870  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6669  clojure.lang.Compiler/analyze
             Compiler.java: 6625  clojure.lang.Compiler/analyze
             Compiler.java: 6001  clojure.lang.Compiler$BodyExpr$Parser/parse
             Compiler.java: 5380  clojure.lang.Compiler$FnMethod/parse
             Compiler.java: 3972  clojure.lang.Compiler$FnExpr/parse
             Compiler.java: 6866  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6669  clojure.lang.Compiler/analyze
             Compiler.java: 6924  clojure.lang.Compiler/eval
             Compiler.java: 6890  clojure.lang.Compiler/eval
                  core.clj: 3105  clojure.core/eval
                  core.clj: 3101  clojure.core/eval
                  main.clj:  240  clojure.main/repl/read-eval-print/fn
                  main.clj:  240  clojure.main/repl/read-eval-print
                  main.clj:  258  clojure.main/repl/fn
                  main.clj:  258  clojure.main/repl
                  main.clj:  174  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   83  nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  646  clojure.core/apply
                  core.clj: 1881  clojure.core/with-bindings*
                  core.clj: 1881  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   81  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   50  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  221  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  189  nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1149  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  624  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  748  java.lang.Thread/  Show: Project-Only All

所以看起来 cider 找不到 -main 函数。也许我应该在另一个地方输入 cider-jack-in 命令?但是哪里? cider-boot-parameters 问题也是 st运行ge。如何使用 boot-clj 和 emacs-25 运行 任何 Clojure 应用程序。 (该问题也发生在 emacs26 和 emacs27)。

我重新安装了 Debian,安装了 boot 和 emacs25。

然后创建配置文件:

s@Windown:~/Dropbox/Clojure/myapp2$ cat ~/.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
(package-initialize)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(cider-boot-parameters (quote "repl -s wait"))
 '(package-selected-packages
   (quote
    (clojure-mode projectile clojure-mode-extra-font-locking cider))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
s@Windown:~/Dropbox/Clojure/myapp2$ 

然后安装了 cider、clojure-mode 和 projectile。然后就成功了。

版本信息

s@Windown:~/Downloads2$ boot -V
#http://boot-clj.com
#Mon Feb 04 13:34:49 CET 2019
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.8.0
BOOT_VERSION=2.8.2
s@Windown:~/Downloads2$ 

This is GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-09-15, modified by Debian

            Emacs Package Library
  projectile         20190126.1117 installed             Manage and navigate projects in Emacs easily
  clojure-mode       20190105.1043 installed             Major mode for Clojure code
  cider              20190125.1339 installed             Clojure Interactive Development Environment that Rocks