Clojure不会吐到results.txt [英] Clojure won't spit to results.txt

查看:185
本文介绍了Clojure不会吐到results.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

立即编辑我得到:无法解决符号:在此上下文中的计数,编译:(C:\Users\Matthew.lein\bin\testingproj\src\testingproj\core.clj:14 :1)

Edit now I get : Unable to resolve symbol: thecount in this context, compiling:(C:\Users\Matthew.lein\bin\testingproj\src\testingproj\core.clj:14:1)

使用以下代码

(defn countstarter [] (let [thecount 0] thecount))
(defn i++ [] (inc thecount))
(defn linetravel [aline thecount]
(nth (split aline #"\s+") (thecount) "nothing found")
)

(defn grammarCHECK [aline  thecount]
(countstarter)
(while (not= linetravel "nothing found")
(do
     (print thecount) (print "debugging function")
  (if (isAFactor linetravel)
         (if (isOpenParen linetravel)
           (isAExpression  linetravel) true)
  false);;know it is not a factor if here




(i++)

)
))

我正在运行

(with-open [r (io/reader "input.txt")]
 (doseq [line (line-seq r)]
  (spit "results.txt"  (grammarCHECK line thecount))
  (spit "output.txt" (str (join "\n" (split line #"\s+")) "\n") :append true)

))

c $ c>(spitresults.txt(grammarCHECK line))

It works fine if I comment out (spit "results.txt" (grammarCHECK line))

但是运行时有以下堆栈,不知道为什么...

but has the following stack when ran with it, and I have no idea why...

推荐答案

(i ++)您正在尝试调用Long在

at line (i++) you are trying to invoke the Long you defined the line before

我试图先给你一个提示... :)

I was trying to first give you a hint.. :)

知道clojure不使用状态与java类似的语言做同样的方式。当你运行(i ++),它被评估为,它看到长定义在某处(希望)。虽然这可能返回所需的新Long值,但它不会更新变量的原始副本 thecount 。这个变量不存在,因为(countstarter)没有效果的原因相同。

You should know that clojure doesnt use state the same way that java-like languages do.. when you run (i++), it gets evaluated into (inc thecount), which sees the long defined somewhere (hopefully). Although this might return the desired new Long value, it wouldnt update the original copy of the variable, thecount. This variable doesnt really exist because the line (countstarter) had no effect for the same reason.

你试图实现?

如果你想有一个有一个状态的循环,你可以使用像下面这样,这不是很clojure的,而是类似于类似于java的编码风格:

If you want to have a loop with some state, you could use something like the following, which is not very clojure-like, rather it resembles java-like coding style:

(loop [state1 0 state2 1]
  (when (< state1 10)
    (println state1 state2)
    (recur (inc state1) (* 2 state2)))

您应该尝试类似 4clojure 的功能,它将帮助您习惯代码是用类似lisp的语言写的

You should try out something like 4clojure, it will help you get used to the way code is written in a lisp-like language

这篇关于Clojure不会吐到results.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆