【问题标题】:What is wrong with (use 'korma.db) directive?(use 'korma.db) 指令有什么问题?
【发布时间】:2014-03-05 19:26:47
【问题描述】:

当我尝试使用 lein 和以下非常简单的 Clojure 测试文件创建 uberjar 时,出现错误

Compiling korma-test.core
Exception in thread "main" java.lang.Exception: 
lib names inside prefix lists must not contain periods, compiling:(core.clj:1:1)

并且不知道为什么。我从sqlkorma.com 的文档部分获得了(use 'korma.db),并尝试了一个require 语句(此处未在我的示例中列出)。

项目.clj

(defproject korma-test "0.1.0-SNAPSHOT"
  :description "korma db test"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [korma "0.3.0-RC5"]]
   :main korma-test.core)

core.clj(简体)

(ns korma-test.core
  (:gen-class)
  (use 'korma.db)
  (require '[clojure.string :as str])
  (:import java.util.Date)
)

(defn -main 
  [& args]
  (let [opts (parse-opts args)
        start-time (str (Date.))]))

【问题讨论】:

  • stackoverflow.com/questions/3719929/… 的部分重复,但这里有两个地方的语法错误,而不仅仅是引用问题。
  • 如果你愿意,我会投票关闭。请告诉我。我不想把事情弄得一团糟。

标签: clojure leiningen korma


【解决方案1】:

ns 宏使用关键字代替函数,并且使用带引号的参数。

(ns korma-test.core
  ...
  (:use korma.db)
  (:require [clojure.string :as str])
  ...)

这里有一篇不错的文章:http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html

【讨论】:

  • 我还建议不要使用use,因为您永远无法确定它在您的命名空间中导入了什么。请改用require (:require [korma.db :as db])。
  • 同意,或者使用:only指令和use来指定。
  • 宾果游戏!非常感谢。
猜你喜欢
  • 2016-02-27
  • 2014-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-02
  • 2014-08-19
相关资源
最近更新 更多