0

Is it possible to inject namespaces in a function in Clojure?

I want my i/o to be outside from the program and only inject it. The problem i faced, that i tried to give a namespace and invoke it i get the error message:

No name namespace: my
(ns mymain
  (:require [myio]))

...

(defn my-test [my]
  (my/showworld))

;(play_game)
(my-test myio)
1
  • 1
    My guess would be, that you need ns-resolve. Commented Jul 11, 2021 at 12:21

1 Answer 1

3

The usual way to pass logic is through functions and not by namespace aliases:

(defn my-test [show-world]
  (show-world))

(require 'myio)
(my-test myio/show-world)
Sign up to request clarification or add additional context in comments.

2 Comments

how do you create a mock object for your namespace?
You usually don't mock namespaces, but you can mock functions e.g. with with-redefs.

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.