Cider: *print-namespace-maps* is always true

Created on 2 May 2018  ·  8Comments  ·  Source: clojure-emacs/cider

Expected behavior, actual behavior and steps to reproduce the problem

Evaluating a map with namespaced keys like
{:person/name "Fred" :person/age 50}
in the cider repl prints the following return value
#:person{:name "Fred", :age 50}
This is due to *print-namespace-maps* defaulting to true.
Normally, it should be possible to change the value of this var permanently with set! thusly:

user> (set! *print-namespace-maps* false)
false
user> *print-namespace-maps*
false

However, the actual behavior is thus:

user> (set! *print-namespace-maps* false)
false
user> *print-namespace-maps*
true

Similarly, it should be possible to temporarily change the var with binding:

user> (binding [*print-namespace-maps* false]
        [*print-namespace-maps* {:person/name "Fred" :person/age 50}])
[false {:person/name "Fred" :person/age 50}]

But, although the var seems to change, the desired behavior remains to be seen;

user> (binding [*print-namespace-maps* false]
        [*print-namespace-maps* {:person/name "Fred" :person/age 50}])
[false #:person{:name "Fred", :age 50}]

CIDER version information

;; CIDER 0.15.0 (London), nREPL 0.2.13
;; Clojure 1.9.0, Java 1.8.0_92

Emacs version

GNU Emacs 24.5.1 (x86_64-apple-darwin15.3.0, NS apple-appkit-1404.34) of 2016-06-01

Operating system

OSX El Capitan, Version 10.11.6

Most helpful comment

I don't know if this is a CIDER specific problem, I can reproduce this issue in a Leiningen REPL.

All 8 comments

I don't know if this is a CIDER specific problem, I can reproduce this issue in a Leiningen REPL.

That suggests it's something to do with nREPL or REPLY's implementation.

https://github.com/cemerick/nREPL/blob/master/src/main/clojure/clojure/tools/nrepl/middleware/interruptible_eval.clj - it looks like the implementation of eval does the right thing, assuming that (get-thread-bindings) does what it's supposed to do. The implementation in Clojure 1.9 looks fine and it does the right thing at the REPL. This suggests that nREPL's session management or something upstream of it isn't capturing and restoring *print-namespace-maps* correctly.

https://github.com/cemerick/nREPL/blob/master/src/main/clojure/clojure/tools/nrepl/middleware/session.clj#L108 - this may be a tiny bit suspect, it doesn't know about *print-namespace-maps* but that doesn't have to be a problem.

clojure.main/with-bindings establishes root bindings for anything that goes through clojure.main/repl, which includes pushing the *print-namespace-maps* default binding of true. The root definition of *print-namespace-maps* in clojure/core_print.clj is false. This behavior can be confirmed with clj -e "(get-thread-bindings)" which will report that {#'clojure.core/*print-namespace-maps* true ...}.

That suggests it's something to do with nREPL or REPLY's implementation.

I doubt that REPLy is doing anything special on top of nREPL, so likely an nREPL problem.

clojure.main binds print-namespace-maps and then retains its value across evaluations in the repl. I'm not sure how to do the equivalent in nrepl, but that's what's needed.

I analysed this a while ago in the relevant Cursive issue: cursive-ide/cursive#1541.

Should I repeat the issue at https://github.com/clojure/tools.nrepl and close it here, @bbatsov ?

@Reefersleep Almost.

https://github.com/clojure/tools.nrepl was succeeded by https://github.com/nrepl/nrepl. Please, submit the ticket there.

Reposted this issue at the nrepl repo as @bbatsov believes the error lies here: https://github.com/nrepl/nREPL/issues/33

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oskarkv picture oskarkv  ·  5Comments

geokon-gh picture geokon-gh  ·  9Comments

ukriish picture ukriish  ·  6Comments

MicahElliott picture MicahElliott  ·  7Comments

bhb picture bhb  ·  5Comments