小编bda*_*els的帖子

同一命名空间中的Clojure deftype调用函数抛出"java.lang.IllegalStateException:Attempting to called unbound fn:"

我将Clojure放入现有的Java项目中,该项目大量使用Jersey和Annotations.我希望能够利用以前工作的现有自定义注释,过滤器等.到目前为止,我已经大致使用了在Clojure Programming第9章中找到的javax.ws.rs注释的deftype方法.

(ns my.namespace.TestResource
  (:use [clojure.data.json :only (json-str)])
  (:import [javax.ws.rs DefaultValue QueryParam Path Produces GET]
           [javax.ws.rs.core Response]))

;;My function that I'd like to call from the resource.
(defn get-response [to]
  (.build
    (Response/ok
      (json-str {:hello to}))))

(definterface Test
  (getTest [^String to]))

(deftype ^{Path "/test"} TestResource [] Test
  (^{GET true
     Produces ["application/json"]}
  getTest
  [this ^{DefaultValue "" QueryParam "to"} to]
  ;Drop out of "interop" code as soon as possible
  (get-response to)))
Run Code Online (Sandbox Code Playgroud)

从注释中可以看出,我想调用deftype之外的函数,但是在同一个命名空间内.至少在我看来,这允许我将deftype专注于interop并连接到Jersey,并且应用程序逻辑是独立的(更像我想写的Clojure).

但是,当我这样做时,我得到以下异常:

java.lang.IllegalStateException: Attempting to call unbound fn: #'my.namespace.TestResource/get-response
Run Code Online (Sandbox Code Playgroud)

deftype和名称空间有什么独特之处吗?

interop annotations clojure

7
推荐指数
1
解决办法
1333
查看次数

是否有一个很好的库可以在scala(或java)应用程序中嵌入命令提示符

我有一个应用程序,我想提示.如果它有帮助,这是一个图形数据库实现,我需要一个提示,就像任何其他数据库客户端(MySQL,Postgresql等).

到目前为止,我有自己的REPL,如下所示:

object App extends Application {
    REPL ! Read
}

object REPL extends Actor {
    def act() {
        loop {
            react {
                case Read => {
                    print("prompt> ")
                    var message = Console.readLine
                    this ! Eval(message)
                }
                case More(sofar) => {
                    //Eval didn't see a semicolon
                    print("    --> ")
                    var message = Console.readLine
                    this ! Eval(sofar + " " + message)
                }
                case Eval(message) => {
                    Evaluator ! Eval(message)
                }
                case Print(message) => {
                    println(message)
                    //And here's the loop
                    this …
Run Code Online (Sandbox Code Playgroud)

java console client scala

3
推荐指数
1
解决办法
644
查看次数

标签 统计

annotations ×1

client ×1

clojure ×1

console ×1

interop ×1

java ×1

scala ×1