English 中文(简体)
Clojure CLR with multi namespaces
原标题:Clojure CLR with multiple namespaces

我写了一个小名称空间,以开展一些数据库业务,我想从另一个名称空间使用。 通常把档案放在同一目录中,然后做

(ns program (:require [other-ns :as other]) (:gen-class))

这些都是必要的。 然而,在Clojure CLR,编辑者抱怨不知道其他人。 因此,这样做的适当方法是什么? 每一名称空间都有适当组合?

另一实例

页: 1

  (ns another)

  (defn hello [name] (str "Hello " name))

方案

  (ns program
    (:require [another :as a])
    (:gen-class))

I load up 方案 in the repl and get this message:

FileNotFoundException Could not locate 页: 1.dll or 页: 1 on load path. clojure.lang.RT.load (d:workclojure-clrClojureClojureLibRT.cs:3068)

问题回答

我在同一目录中设立了两个档案。 页: 1

(ns filea)

(defn hi []
  (println "hi from filea"))

Here s fileb.clj:

(ns fileb
  (require [filea :as a])
  (:gen-class))

(defn -main []
  (println "hi from fileb")
  (a/hi))

I then changed into the directory where these files live and ran:

C: empmulti-ns>clojure.compile fileb Compiling fileb to . -- 59 milliseconds.

当我跑时,我看到:

C: empmulti-ns>c:Toolsclojure-clr-1.3.0-Debug-4.0fileb.exe hi from fileb hi from filea

Are you using vsClojure or writing your code outside of VS?





相关问题
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 ...

热门标签