Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java';Clojure中的s扫描仪_Java_Clojure - Fatal编程技术网

使用Java';Clojure中的s扫描仪

使用Java';Clojure中的s扫描仪,java,clojure,Java,Clojure,我试图使用Java扫描器从clojure的读取行中提取输入。我认为这只是一个基本的错误,对于Clojure来说,这是一个新的错误。代码如下: (defn select-option [] (def option (read-line)) (println "test") (def s (Scanner. option)) (println "test") (def opt (.next s)) (println "test") (case opt ("s" (println "case

我试图使用Java扫描器从clojure的读取行中提取输入。我认为这只是一个基本的错误,对于Clojure来说,这是一个新的错误。代码如下:

(defn select-option
  []

(def option (read-line))
(println "test")
(def s (Scanner. option))
(println "test")
(def opt (.next s))
(println "test")

(case opt ("s"  (println "case test")
                (def lastn (.next s))
                (def firstn (.next s))
                (new-student lastn firstn))))
但我在输入“s firstName lastName”时得到以下输出


我会认为这是我使用java代码时的一个错误,但是非常感谢您的帮助,谢谢

(“s”)
中有一组额外的参数,它被解释为对函数“s”的函数调用。这会崩溃,因为“s”不是函数。最好使用
let
在函数中定义名称,因为在这里使用
def
对于并发操作是不安全的

一个翻译可以是这样的:

(defn select-option []                       
  (let [option (read-line)                   
        _ (println "test")                   
        s (Scanner. option)                  
        _ (println "test")                   
        opt (.next s)                        
        _ (println "test")]                  
    (case opt                                
       "s"  (println "case test")             
      (let [lastn (.next s)                  
            firstn (.next s)]                
        (new-student lastn firstn)))))  

Def始终定义一个顶级变量,因此如果在函数中使用它,该函数的所有实例将共享相同的值并相互干扰。在Clojure中,定义词法范围的结构是
let
表达式。在上面的示例中,我使用名称
\uuuu
来表示我不打算处理的值(打印的结果),这只是一种约定,尽管它表明在let表达式中多次使用相同的名称是可以的(以后的表达式如果愿意,可以使用以前的值)

我很难找到额外的括号,谢谢!从目前的情况来看,这是非常不合法的,我原本让它存在,但为了修复它,我改变了它。再次感谢!Paredit(用于emacs和vim)是一个令人痛苦的。。。要学习,尽管它很容易上瘾,并且会让额外的()s(不完全)消失。我在使用它的时候几乎不在乎它。
(defn select-option []                       
  (let [option (read-line)                   
        _ (println "test")                   
        s (Scanner. option)                  
        _ (println "test")                   
        opt (.next s)                        
        _ (println "test")]                  
    (case opt                                
       "s"  (println "case test")             
      (let [lastn (.next s)                  
            firstn (.next s)]                
        (new-student lastn firstn)))))