murtaza52
murtaza52

Reputation: 47441

same function from two ns clashes in repl

In my repl I have loaded ns from one file that has a function parse. So (use 'demo.one) works fine when typed in the repl.

Now I have another ns which has a function with the same name. When I type this `(use 'demo.two), it gives me an error.

How do I prevent the function name clashes in both the ns ? In the above I would like to use the function from the second ns only.

Thanks

Upvotes: 1

Views: 56

Answers (2)

Abimaran Kugathasan
Abimaran Kugathasan

Reputation: 32458

There’s also a way to alias namespaces when you require them,

You can use :as with :require

(ns your.namespace
(:require [demo.one :as one])
(:require [demo.two :as two]))

(one/parse "foo") ; use the namespace demo.one parse function
(two/parse "foo") ; use the namespace demo.two parse function

Upvotes: 2

tom
tom

Reputation: 19153

You can avoid clashes by requireing the namespace, and then fully qualifying your function call.

e.g.

(require 'demo.two)
(demo.two/parse "foo")

Upvotes: 2

Related Questions