Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Function In Separate Clojure Namespace

Tags:

clojure

How do I call a function in one Clojure namespace, bene-csv.core from another namespace, bene-cmp.core? I've tried various flavors of :require and :use with no success.

Here is the function in 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))

Here is the header of bene-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)
  .
  .
  .

The calling function -- currently a stub -- in (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]))

If I modify the header of bene-cmp.clj

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

and change the call to ret-csv-data

(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]))

I get this error

Caused by: java.lang.RuntimeException: No such var: bcsv/ret-csv-data

So, how do I call fetch-csv-data? Thank You.

like image 640
octopusgrabbus Avatar asked Apr 04 '12 16:04

octopusgrabbus


1 Answers

You need to invoke the function, not just reference the var.

If you have this in your ns:

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

Then you need to put parentheses around the namespace/alias qualified var to invoke it:

(let [benetrak-csv-data (bcsv/ret-csv-data arg)]
  ; stuff
  )
like image 114
Jeremy Avatar answered Oct 13 '22 06:10

Jeremy