# Why use cider-send-ns-form-to-repl instead of cider-send-function-to-repl in Emacs Cider?

**URL:** https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066
**Category:** Beginners
**Tags:** clojure, cider, emacs
**Created:** [January 21, 2021, 5:48pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066 "2021-01-21T17:48:11Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Mert\_Nuhoglu](https://clojureverse.org/user_avatar/clojureverse.org/mert_nuhoglu/32/2711_2.png) [@Mert\_Nuhoglu](https://clojureverse.org/u/Mert_Nuhoglu)
#### Post date: [January 21, 2021, 5:48pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/1 "2021-01-21T17:48:11Z")

</div>

Is there any difference between `cider-send-ns-form-to-repl` and `cider-send-function-to-repl`?

For example, I have the following form in my clj file:

```
(ns e01.rebl-examples
  (:import java.io.File)
  (:require [clojure.java.io :as io]
            [clojure.core.protocols :as p]))

```

I can send this form to repl using both commands. I’d prefer `cider-send-function-to-repl` because I can use it with any form.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 21, 2021, 6:10pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/2 "2021-01-21T18:10:11Z")

</div>

`cider-send-ns-form-to-repl` will send the ns form no matter where your cursor is in the file.

---

<div class="post-metadata">

### Author: ![Phill](https://clojureverse.org/letter_avatar_proxy/v4/letter/p/779978/32.png) [@Phill](https://clojureverse.org/u/Phill)
#### Post date: [January 21, 2021, 6:16pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/3 "2021-01-21T18:16:22Z")

</div>

Does Cider also send the ns form when evaluating any form?

---

<div class="post-metadata">

### Author: ![mvarela](https://clojureverse.org/user_avatar/clojureverse.org/mvarela/32/1478_2.png) [@mvarela](https://clojureverse.org/u/mvarela)
#### Post date: [January 21, 2021, 7:48pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/4 "2021-01-21T19:48:27Z")

</div>

No, it doesn’t.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 22, 2021, 6:35pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/5 "2021-01-22T18:35:28Z")

</div>

> [@Phill](#):
>
> Does Cider also send the ns form when evaluating any form?

Yes and no.

There’s the send to repl functions. And there’s the eval functions.

The send to repl functions are like if you copy/pasted things in the REPL window and pressed enter. So they are executed in the context of your REPL window. So if you send some defn form it will just send that. It won’t send anything else.

The eval functions evaluate the form within the context of the first ns form found backward from the form you are evaluating. So if you evaluate some defn and above the defn you have `(ns foo)` and your REPL window is in the `user` namespace, Cider will switch to foo and evaluate the defn, but it’s not switching your REPL window, in the REPL window you are still going to be inside the user namespace.

The output of the send to repl functions will show in the REPL window.

The output of the eval functions will show inline with the code.

---

<div class="post-metadata">

### Author: ![mvarela](https://clojureverse.org/user_avatar/clojureverse.org/mvarela/32/1478_2.png) [@mvarela](https://clojureverse.org/u/mvarela)
#### Post date: [January 22, 2021, 6:46pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/6 "2021-01-22T18:46:19Z")

</div>

Yes, forms in an ns are evaluated in that ns, but the ns form itself is not evaluated if you don’t do it explicitly (so requires and imports are not available until you do)

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 22, 2021, 7:38pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/7 "2021-01-22T19:38:55Z")

</div>

Ya, I don’t remember what it does exactly, I had looked it up a while ago. I think it might just call `in-ns` or maybe it just `binds` `*ns*`. If it does the former, it would create the namespace if it didn’t exist, but otherwise would just switch to it without requiring or importing anything.

---

<div class="post-metadata">

### Author: ![mvarela](https://clojureverse.org/user_avatar/clojureverse.org/mvarela/32/1478_2.png) [@mvarela](https://clojureverse.org/u/mvarela)
#### Post date: [January 23, 2021, 5:04pm UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/8 "2021-01-23T17:04:21Z")

</div>

I’m too lazy to go dig into the code now, but it looks like it’s calling `in-ns`.

```
(ns toto) ;; never evaluated from the buffer

(defn add [a b]
  (+ a b))
;; => #'toto/add
```

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [July 25, 2021, 5:04am UTC](https://clojureverse.org/t/why-use-cider-send-ns-form-to-repl-instead-of-cider-send-function-to-repl-in-emacs-cider/7066/9 "2021-07-25T05:04:22Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
