English 中文(简体)
使瓦尔人能够适当控制多个档案
原标题:Getting Vars to bind properly across multiple files
  • 时间:2010-03-20 03:48:25
  •  标签:
  • clojure

我只是学习“衣物”,在把我的法典翻译成不同档案方面遇到麻烦。

我将这一错误从 app子中删除。

Exception in thread "main" java.lang.Exception: Unable to resolve symbol: -run-application in this context

似乎发现名称空间被罚款,但后来却看不见瓦雷斯受到约束...... 如何解决这一问题的想法?

我的守则如下:

附录二

(ns src/apprunner
  (:use src/functions))

(def input-files [(resource-path "a.txt") (resource-path "b.txt") (resource-path "c.txt")])
(def output-file (resource-path "output.txt"))

(defn run-application []
  (sort-files input-files output-file))

(run-application)

任用 -

(ns src/functions
  (:use clojure.contrib.duck-streams))

(defn flatten [x]
  (let [s? #(instance? clojure.lang.Sequential %)]
    (filter
      (complement s?)
      (tree-seq s? seq x))))

(defn resource-path [file]
  (str "C:/Users/Alex and Paula/Documents/SoftwareProjects/MyClojureApp/resources/" file))

(defn split2 [str delim]
  (seq (.split str delim)))

(defstruct person :first-name :last-name)

(defn read-file-content [file]
  (apply str
    (interpose "
" (read-lines file))))

(defn person-from-line [line]
  (let [sections (split2 line " ")]
    (struct person (first sections) (second sections))))

(defn formatted-for-display [person]
  (str (:first-name person) (.toUpperCase " ") (:last-name person)))

(defn sort-by-keys [struct-map keys]
  (sort-by #(vec (map % [keys])) struct-map))

(defn formatted-output [persons output-number]
  (let [heading (str "Output #" output-number "
")
        sorted-persons-for-output (apply str (interpose "
" (map formatted-for-display (sort-by-keys persons (:first-name :last-name)))))]
    (str heading sorted-persons-for-output)))

(defn read-persons-from [file]
  (let [lines (read-lines file)]
    (map person-from-line lines)))

(defn write-persons-to [file persons]
  (dotimes [i 3]
    (append-spit file (formatted-output persons (+ 1 i)))))

(defn sort-files [input-files output-file]
  (let [persons (flatten (map read-persons-from input-files))]
    (write-persons-to output-file persons)))
最佳回答

你不要正确点名!

我们应该这样做:


;;; in file src/apprunner/core.clj
;;; (namespace names should contain at least one dot for things
;;; not to go into the default package... or some such thing)
(ns apprunner.core
  (:use apprunner.functions)

;;; the rest of your code for this file follows unchanged

;;; in file src/apprunner/functions.clj
(ns apprunner.functions
  (:use clojure.contrib.duck-streams))

;;; the rest of your code for this file follows unchanged

上文在REPL((use apprunner.core)等处对我课以罚款。

1. 概述问题: 姓名应当包含一些斜体,在这些地方,对文件加以限定的路由斜线/斜线(而不是我指的是relative条线——相对于实际上在舱面上的某些目录。 另外,<代码>src/的名录是你在舱面上填写的,因此你没有在座标上填写<代码>src.。 See e.g. the src/foo/bar/baz.clj vs. foo.bar.baz 例如,在我对

Oh,顺便说一遍,时间很困难。 因此,确保不要让 yourself受到此类问题的影响! 如果你提出更多的名称空间或与阶级有关的问题,或者如果上述问题没有解决你的问题,那么你可能希望列入如何操作你的代码。

问题回答

暂无回答




相关问题
How to improve Clojures error messages

I ve been playing a bit with Clojure and so far is fairly impressed, but one thing that I keep running into is wierd error messages from Clojure. This comes in two forms: Java errors, like null ...

clojure rmi classpath problem

I am trying to use clojure to implement a "plugin" for some vendor supplied software. Here is a little background on the vendor supplied software. It expects me to implement a particular interface ...

Help translating this Java codeblock to Clojure?

I m getting my feet wet with Clojure, and trying to get used to functional programming. I ve been translating various imperative functions from other languages into their Clojure equivalents -- and ...

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand s suggestion. (defn redux [[current next] flag] [(if flag ...

taking java method names as function arg in clojure

All, I want to create a function that takes a symbol representing a java method and applies it to some object: (user=> (defn f [m] (. "foo" (m))) When I execute this, I get a result much ...

how to efficiently apply a medium-weight function in parallel

I m looking to map a modestly-expensive function onto a large lazy seq in parallel. pmap is great but i m loosing to much to context switching. I think I need to increase the size of the chunk of work ...

热门标签