【问题标题】:Cannot use defroutes macro from compojure无法使用 compojure 中的 defroutes 宏
【发布时间】:2016-07-13 10:04:28
【问题描述】:

运行此代码时:

(:使用'compojure.core) (键(ns-publics 'compojure.core)) (defroutes 应用程序路由 (GET "/" [] "Hello World") (路线/资源“/”) (路线/未找到“未找到”))

我收到了这条消息:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: defroutes in this context, 编译:(restful_clojure\routes.clj:5:1)

但是当我跑步时:

(键(ns-publics 'compojure.core))

它表明定义了宏:

(defroutes PUT POST 路由路由 make-route let-routes DELETE ANY let-request GET HEAD PATCH context OPTIONS)

【问题讨论】:

  • 您能否发布整个文件并描述您如何运行代码?我刚刚在终端中使用类路径上的 compojure 启动 REPL,它可以工作。

标签: clojure macros compojure


【解决方案1】:

Clojure 有方法 requireimportreferuse。这些用于处理不同的命名空间。

:use 是一个Keyword,它的行为可以像一个函数(在你的例子中它应该返回nil),但不会做你想做的事情。

混淆可能是由于ns macro中,您可以使用相应的关键字“嵌入”这些函数的行为。

有关命名空间的更多信息,请参阅link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 2015-01-18
    • 2017-09-03
    相关资源
    最近更新 更多