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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
特定学年的Clojure报税表_Clojure - Fatal编程技术网

特定学年的Clojure报税表

特定学年的Clojure报税表,clojure,Clojure,我已经试着运行我的代码,但是我得到了一个语法错误 读取源代码时出现语法错误(年份代码.clj:32:1) 从第12行开始读取时的EOF 我是否遗漏了什么,或者我的代码有什么问题 您的yearCode函数中的括号有一些问题。您在defn和yearCode之间有一个额外的(),如果表达式需要括号,则最后两个: (defn(yearCode [year] (if (= year "freshman") 1 (if (= year "sophomore") 2

我已经试着运行我的代码,但是我得到了一个语法错误

读取源代码时出现语法错误(年份代码.clj:32:1)

从第12行开始读取时的EOF


我是否遗漏了什么,或者我的代码有什么问题

您的
yearCode
函数中的括号有一些问题。您在
defn
yearCode
之间有一个额外的
),如果
表达式需要括号,则最后两个

(defn(yearCode [year]
    (if (= year "freshman") 1
        (if (= year "sophomore") 2
            if (= year "junior") 3
               if (= year "senior") 4 0) 
             )
         )
    )
)


(defn -main []
    (println "\n To find your year:") 
    (print "enter your year: ") (flush) 
    (let 
    [ year (read) ]
        (print "\n your year is ") 
        (print (yearCode year))
        (print "\n\n") 
    )
 )
但是,您可能会发现使用
案例
更容易:

(defn yearCode [year]
    (if (= year "freshman") 1
        (if (= year "sophomore") 2
            (if (= year "junior") 3
                (if (= year "senior") 4 0)))))
或地图:

(defn yearCode [year]
  (case year
    "freshman" 1
    "sophomore" 2
    "junior" 3
    "senior" 4
    0))
您还应该在主函数中使用
read line
而不是
read
read
将结果转换为clojure格式,而
read line
直接返回字符串

(def yearCodes
  {"freshman" 1
   "sophomore" 2
   "junior" 3
   "senior" 4})

(defn yearCode [year]
  (get yearCodes year 0))

您的
yearCode
函数中的括号有一些问题。您在
defn
yearCode
之间有一个额外的
),最后两个
if
表达式需要括号:

(defn(yearCode [year]
    (if (= year "freshman") 1
        (if (= year "sophomore") 2
            if (= year "junior") 3
               if (= year "senior") 4 0) 
             )
         )
    )
)


(defn -main []
    (println "\n To find your year:") 
    (print "enter your year: ") (flush) 
    (let 
    [ year (read) ]
        (print "\n your year is ") 
        (print (yearCode year))
        (print "\n\n") 
    )
 )
但是,您可能会发现使用
案例
更容易:

(defn yearCode [year]
    (if (= year "freshman") 1
        (if (= year "sophomore") 2
            (if (= year "junior") 3
                (if (= year "senior") 4 0)))))
或地图:

(defn yearCode [year]
  (case year
    "freshman" 1
    "sophomore" 2
    "junior" 3
    "senior" 4
    0))
您还应该在主函数中使用
read line
而不是
read
read
将结果转换为clojure格式,而
read line
直接返回字符串

(def yearCodes
  {"freshman" 1
   "sophomore" 2
   "junior" 3
   "senior" 4})

(defn yearCode [year]
  (get yearCodes year 0))

最重要的是函数名前面不应该有
(你的
-main'
是正确的),如果需要用
()
s包装,那么最后两个
。修复它们,然后看看它说了什么。你有一个额外的
介于
defn
yearCode
之间。仅供参考,如果
s使用
大小写
表达式,您可以替换嵌套的
。您还应该在代码中包含行号。
year\u代码。clj:32:1
表示问题出现在第32行。从第12行开始的
EOF表示您已经解决了问题ced圆括号(起始位置)。最重要的是函数名前面不应该有
(你的
-main'
是正确的),如果需要用
()
s包装,那么最后两个
。修复它们,然后看看它说了什么。你有一个额外的
介于
defn
yearCode
之间。仅供参考,如果
s使用
大小写
表达式,您可以替换嵌套的
。您还应该在代码中包含行号。
year\u代码。clj:32:1
表示问题出现在第32行。从第12行开始的
EOF表示您已经解决了问题ced圆括号(起始位置)。谢谢!我想我已经掌握了窍门。但是,我认为我的主函数可能有一些问题。文件仍然没有编译:/clojure.main/main(main.java:40)处的执行错误.No命名空间:年份代码found@hkira1-错误是什么?你的
main
函数为我编译,因此听起来你的错误好像在其他地方。你能编辑你的问题以包含所有的代码吗?我将它加载到REPL中,它按预期工作。你从命令行使用什么命令?@hkira1-什么是
ns
声明在您的文件中?您需要一个
(ns年\u代码)
语句在您的文件顶部。@hkira1-抱歉,我意识到您的
-main
函数中也有一个小错误,请参阅更新。谢谢!我想我已经掌握了诀窍。但是,我想我的主函数可能有一些问题。文件仍然没有编译:/clojure.main/main处的执行错误(main.java:40).No命名空间:年份代码found@hkira1-错误是什么?你的
main
函数为我编译,因此听起来你的错误好像在其他地方。你能编辑你的问题以包含所有的代码吗?我将它加载到REPL中,它按预期工作。你从命令行使用什么命令?@hkira1-什么是
ns
声明在您的文件中?您需要在文件顶部有一个
(ns year\U code)
语句。@hkira1-抱歉,我意识到您的
-main
函数也有一个小错误,请参阅更新。