6

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.

1 Answer 1

8

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
  )
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I was referencing the var instead of calling the function. At least my :require instincts were good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.