繁体   English   中英

nrepl.el和leiningen 2默认命名空间?

[英]nrepl.el and leiningen 2 default namespace?

让Emacs / Clojure环境启动并运行,我现在遇到了我不确定是正常的行为。 特别是,当我启动一个nREPL并编译(Cc Ck)我的缓冲区时,我会被放到我的core.clj文件顶部定义的命名空间之外。 我应该添加免责声明,我对Clojure和名称空间有点新,所以我对这一切的理解可能是模糊的。 我愿意接受那些能够让我看到Better Way™的自以为是的答案。

首先,关于我的设置:

我的emacs环境是Cocoa Emacs 24,主要使用Melpa存储库中的emacs入门工具包进行设置,并通过包管理器添加了clojure和nrepl包。

我的leiningen 2项目是使用lein new test-clj

我的project.clj

(defproject test-clj "0.1.0-SNAPSHOT"
  :description "A geospatial test app example mostly ripped off from http://datamangling.com/blog/2010/05/26/geotools-quickstart-in-clojure/"
  :repositories {"osgeo-geotools" "http://download.osgeo.org/webdav/geotools"}
  :url "FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [org.geotools/gt-main "8.2"]
                 [org.geotools/gt-shapefile "8.2"]
                 [org.geotools/gt-epsg-hsql "8.2"]
                 [org.geotools/gt-swing "8.2"]])

我的core.clj

(ns test-clj.core
  (:import [org.geotools.data CachingFeatureSource FeatureSource FileDataStore FileDataStoreFinder])
  (:import [org.geotools.map DefaultMapContext MapContext])
  (:import [org.geotools.swing JMapFrame])
  (:import [org.geotools.swing.data JFileDataStoreChooser]))


(defn show-shapefile
  "Prompts the user for a shapefile and displays its content"
  []
  (if-let [shapefile (JFileDataStoreChooser/showOpenFile "shp" nil)]
    (let [fs (.getFeatureSource (FileDataStoreFinder/getDataStore shapefile))]
      (doto (DefaultMapContext.)
        (.setTitle "Quickstart")
        (.addLayer fs nil)
        (JMapFrame/showMap)))))

我应该能够

  1. 加载我的core.clj文件和jack-in( Mx nrepl-jack-in
  2. Cc Ck将缓冲区加载到REPL中
  3. 输入(show-shapefile)并对我的聪明才智印象深刻

实际上,我得到的错误看起来像clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: show-shapefile in this context, compiling:(NO_SOURCE_PATH:1)

如果,从REPL我第一次输入(in-ns`test-clj.core),我就是金色的。 另外,如果我输入(test-clj.core / show-shapefile)我就设置了。

当我在逆时针加载REPL时,我会自动进入test-clj.core命名空间,这似乎很方便。

我的问题是双重的:

  1. 这是我看到的正确行为吗? (即我只是懒惰?)
  2. 有没有办法放入这个命名空间(或者相反,告诉我这是一个愚蠢的想法)?

只需对您的工作流程进行一些更改:

  1. 加载我的core.clj文件和jack-in( Mx nrepl-jack-in)
  2. Cc Cl加载文件
  3. cc Mn将repl切换到命名空间
  4. 输入(show-shapefile)并对我的聪明才智印象深刻

第2步编译文件,创建命名空间
步骤3比切换到repl并运行in-ns

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM