Mari
Mari

Reputation: 189

How can I just public expose some functions of my namespace in Clojure?

I have the following code:

(ns mylib-clojure.core)

(defn foo2 [x]
  (inc x))

(defn foo1 [x]
  (foo2 x))

Function foo2 is just used internally inside foo1. Let's say I don't want to expose function foo2 so I have a smaller API provided for users of my namespace. Is it possible to make foo2 "private"?

Upvotes: 1

Views: 230

Answers (1)

Jarlax
Jarlax

Reputation: 1576

You can declare foo2 as "private":

(defn- foo2 [x] (inc x))

It will be not visible outside mylib-clojure.core. Documentation of defn- can be found here. Another option is to declare it inside foo1:

(defn foo1 [x]
  (let [foo2 (fn [x] (inc x))]
    (foo2 x)))

Upvotes: 3

Related Questions