2012-04-04 63 views
4

如何在一個Clojure命名空間中調用函數,來自另一個命名空間的bene-csv.core,bene-cmp.core?我嘗試了各種口味:要求和:使用沒有成功。在單獨的Clojure命名空間中調用函數

這裏是在功能BENE-CSV:

(defn ret-csv-data 
    "Returns a lazy sequence generated by parse-csv. 
    Uses open-csv-file which will return a nil, if 
    there is an exception in opening fnam. 

    parse-csv called on non-nil file, and that 
    data is returned." 

    [fnam] 
    (let [ csv-file (open-csv-file fnam) 
      csv-data (if-not (nil? csv-file) 
         (parse-csv csv-file) 
         nil)] 
      csv-data)) 

這裏是好處-cmp.core頭:

(ns bene-cmp.core 
    . 
    . 
    . 
    (:gen-class) 
    (:use [clojure.tools.cli]) 
    (:require [clojure.string :as cstr]) 
    (:use bene-csv.core) 
    (:use clojure-csv.core) 
    . 
    . 
    . 

調用函數 - 當前存根 - 在( BENE-cmp.core)

defn fetch-csv-data 
    "This function merely loads the two csv file arguments." 

    [benetrak-csv-file gic-billing-file] 
     (let [benetrak-csv-data ret-csv-data])) 

如果我修改好處-cmp.clj的報頭

(:require [bene-csv.core :as bcsv]) 

並更改呼叫RET-CSV數據所致

(defn fetch-csv-data 
    "This function merely loads the two csv file arguments." 

    [benetrak-csv-file gic-billing-file] 
     (let [benetrak-csv-data bcsv/ret-csv-data])) 

我得到這個錯誤

:了java.lang.RuntimeException:沒有這樣的變種:BCSV/RET-csv- data

那麼,如何調用fetch-csv-data? 謝謝。

回答

6

您需要調用該函數,而不僅僅引用var。

如果你有這個在你ns

(:require [bene-csv.core :as bcsv]) 

然後,你需要把括號圍繞命名空間/別名合格VAR來調用它:

(let [benetrak-csv-data (bcsv/ret-csv-data arg)] 
    ; stuff 
) 
+0

謝謝。我引用了var而不是調用該函數。至少我的:要求本能是好的。 – octopusgrabbus 2012-04-04 16:50:57