相关疑难解决方法(0)

Clojure(读取行)返回nil; 没有提示

我正在研究我的第一个适当的Clojure程序 - 国际象棋游戏.我有以下内容:

(defn human-move [board]
  (board-utils/print-board board)
  (print "Enter your move, like this: 'E7 E5' ...")
  (loop [raw-move (terminal-input)] ;;(read-line)]
    (println "I just received" raw-move)
    (if (re-matches #"[A-H][1-8]\s[A-H][1-8]" raw-move)
      (parse-move raw-move)
      (do
        (println "Invalid format! There should be a letter, number, space, letter, and final number.")
        (print "Try again: ")
        (recur (read-line))))))
Run Code Online (Sandbox Code Playgroud)

请注意read-line注释掉并替换为的位置terminal-input.read-line给了我一个NullPointerException,所以出于诊断目的:

(defn terminal-input []
  (println "input")
  (let [whatnot (read-line)]
    (println "received" whatnot)
    whatnot))
Run Code Online (Sandbox Code Playgroud)

然后,当我打电话human-move.

...
+---+---+---+---+---+---+---+---+
| P | …
Run Code Online (Sandbox Code Playgroud)

clojure

5
推荐指数
2
解决办法
1056
查看次数

在leiningen测试中,clojure read-line失败了

我正在测试一些音频行为,我需要用户判断事情是否通过.我想请用户在leiningen测试中做出回应.但是,有一些事情发生在读取线上,阻止了这一点.

这是使用"lein new foo"创建新的clojure项目并编辑foo/test/foo/core_test.clj文件之后的一些示例测试代码:

(ns foo.core-test
  (:use clojure.test
        foo.core))

(deftest a-test
  (testing "FIXME, what a fail."
    (let [_ (println "enter something")
          yn (read-line)]
      (println yn)
      (is (= yn "y")))))
Run Code Online (Sandbox Code Playgroud)

这就是"lein测试"中发生的事情

lein test foo.core-test
enter something
hi
there
what
is 
going on?
^C
Run Code Online (Sandbox Code Playgroud)

只有control-C停止(读取线路)呼叫.

我在Java 1.6.0_35 Java HotSpot(TM)64位服务器VM上使用Clojure 1.4.0和Leiningen 2.0.0-preview7

关于如何让读取线在测试中工作的任何想法?

我还应该注意(read-line)在我的"lein repl"中运行良好...

> lein repl
nREPL server started on port 54398
REPL-y 0.1.0-beta8
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source …
Run Code Online (Sandbox Code Playgroud)

clojure leiningen

5
推荐指数
1
解决办法
355
查看次数

Clojure REPL无法解析符号

从lein run执行此功能时,程序按预期执行.但我正在尝试使用atom.io的proto-repl包,当我使用proto-repl调用该函数时,它会给出一个"CompilerException java.lang.RuntimeException:无法解析符号:在这种情况下可以投票".这是我的功能:

(defn can-vote
  []
   (println "Enter age: ")
   (let [age (read-line)]
    (let [new-age (read-string age)]
     (if (< new-age 18) (println "Not old enough")))
      (println "Yay! You can vote")))
Run Code Online (Sandbox Code Playgroud)

clojure runtimeexception

2
推荐指数
1
解决办法
5630
查看次数

标签 统计

clojure ×3

leiningen ×1

runtimeexception ×1