确定为什么Clojure REPL(加载文件)和蛋糕生成良率错误 [英] Determining Why Clojure REPL (load-file) and cake build yield error

查看:113
本文介绍了确定为什么Clojure REPL(加载文件)和蛋糕生成良率错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Clojure 1.3开始,我对在Clojure中构建某些内容所需的目录结构感到困惑。我正在使用cake来构建和复制蛋糕。

Since Clojure 1.3, I am confused about the directory structure needed to build something in Clojure. I am using cake to build and cake repl.

这是有效的方法。我有一个工作的构建目录addr_verify。主要名称是addr-verify。 project.clj将addr-verify称为main,在addr_verify / src中存在addr_verify.clj。 addr_verify.clj中的ns引用了addr-verify命名空间。

Here is what works. I have a working build directory addr_verify. The main's and ns's name is addr-verify. The project.clj refers to addr-verify as main, and in addr_verify/src there is addr_verify.clj. The ns inside addr_verify.clj refers to the addr-verify name space.

现在,我有一个目录mr1,但是cake无法在第1行正确编译它

Now, I had a directory mr1, but cake won't compile it right at line 1

(ns mr1
  (use ['clojure.string :only '(split)])
  (use ['clojure.string :only '(join)])
  )

如果mr1是一个不好的名字,我应该使用什么命名约定?

If mr1 is a bad name, what naming convention should I use?

我尝试将mr1_app作为目录结构使用mr1-app作为主要名称和ns名称。我

I have tried mr1_app as a directory structure using mr1-app as the main name and ns name. I

对于mr1作为目录和ns名称,我得到

For mr1 as the directory and ns name, I get

Caused by: clojure.lang.Compiler$CompilerException: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.Comparable, compiling:(mr1.clj:1)

我只是在这里没有弄错我做错的事情,而且我知道这可能真的很简单。

I'm just not getting what I'm doing wrong here, and I know it's probably something really simple.

为什么二进制mr1没有主键?

Why does the binary mr1 not have a main?

mr1 / project.clj

mr1/project.clj

(defproject mr1 "0.0.1-SNAPSHOT"
  :description "TODO: add summary of your project"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [org.clojure/tools.cli "0.1.0"]]
   :main mr1)

mr1 / src / mr1.clj

mr1/src/mr1.clj

(ns mr1
    (:use [clojure.string :only [split]]
          [clojure.string :only [join]]))

(def grid-dim (atom '(0 0)))
(def mr1-pos (atom '(0 0)))
(def mr2-pos (atom '(0 0)))

(defn cvt-str-to-int
    [string]
   (map #(Integer/parseInt %)
    (split string #" ")))

(defn prompt-for-grid-dim
    []
    (do
        (println "Enter the dimensions of the grid (10 10) ")
        (cvt-str-to-int (read-line))
    ))

(defn prompt-for-rover-pos
    [rover-num]
    (do
        (println "Enter rover's initial position on the grid (2 4) ")
        (cvt-str-to-int (read-line))
    ))

(defn prompt-for-rover-moves
    []
    (do
        (println "Enter rover's moves LMMRM ")
        (read-line)
    ))

(defn -main 
    [& args]
    (do
       (reset! grid-dim (cvt-str-to-int (prompt-for-grid-dim)))
       (reset! mr1-pos (cvt-str-to-int (prompt-for-rover-pos)))
    ) 
)


推荐答案

我认为您的命名空间声明的语法有问题。相反,请尝试以下操作:

I think there is something wrong with the "syntax" of your namespace declaration. Instead, try this:

(ns mr1
    (:use [clojure.string :only [split]]
          [clojure.string :only [join]]))

在以下位置更改:main设置因此,project.clj:应该只是 mr1 ,与我之前所说的相反。

Change your :main setting in project.clj accordingly: it should just be mr1, contrary to what I said earlier.

根据评论编辑googolplex

Edited according the comment of googolplex

这篇关于确定为什么Clojure REPL(加载文件)和蛋糕生成良率错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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