簡體   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