Fork me on GitHub
#cider
<
2020-06-09
>
Joshua Suskalo00:06:55

@bozhidar you have any suggestions for my problem, where I'd like to prevent a value which implements IDeref from being derefed when it's pretty printed as a return value in cider?

dpsutton00:06:04

I can look in a bit but I’m guessing it’s an extend method we added to the print mechanism. Should be overridqble back and that is a bug in my view

dpsutton00:06:59

Hmm. This sounds weirder and weirder. Since derefing can trigger blocking and on delays can trigger computation prematurely.

Joshua Suskalo01:06:25

Yeah, I also implement IBlockingDeref and that impl isn't used ever

Joshua Suskalo01:06:11

The problem is I'm trying to implement custom promises in order to prevent a breaking change to my api, but I don't want to have to require my users have cider or nrepl on their classpath to run the application, but I also don't want it to hang if they try something out on the repl

dpsutton01:06:00

Yeah agreed

dpsutton01:06:20

Hopefully there’s a way to fix up in code without waiting on a release

dpsutton01:06:05

(def ^:dynamic pretty-objects "If true, cider prettifies some object descriptions. For instance, instead of printing functions as #object[clojure.core$PLUS 0x4e648e99 \"clojure.core$PLUS@4e648e99\"] they are printed as #function[clojure.core/+] To disable this feature, do (alter-var-root #'cider.nrepl.print-method/pretty-objects not)" true)

dpsutton01:06:22

You can turn it off with that dynamic var. can probably easily redef the print-method for ideref in your repl and that should be removed I think

dpsutton04:06:27

@suskeyhose i'm looking into this some more. I see that the printer for the c.l.IDeref checks to see if a) its also IPending and b) if so, if its realized. (https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_print.clj#L436-L457). Is it possible for you to also add IPending to your custom promise types such that the printer works better? I still think this is a bug in cider-nrepl but this also might allow you to add a bit more onto your type to make it a bit better as well

dpsutton04:06:34

I'm actually less convinced this is a bug. in a bare clj repl:

~/p/d/cider-nrepl ❯❯❯ clj
Clojure 1.10.1
user=> (reify clojure.lang.IDeref (deref [_] (do (prn "i'm gonna sleep a while") (Thread/sleep 3000) :slept/value)))
"i'm gonna sleep a while"
#object[user$eval136$reify__137 0x29182679 {:status :ready, :val :slept/value}]
user=>
just printing the reify will cause it to deref. the printer side-effects that. You need to add the IPending instead

bozhidar05:06:45

Seems I’m late to this conversation and you’ve made plenty of progress without me. Might be a good idea to move this to some issue, so that the important points won’t get lost with the Slack history.

Parenoid08:06:26

cross post alert! posted in #clojurescript, too...

Parenoid08:06:29

to try the code at https://www.learn-clojurescript.com/section-1/lesson-8-capstone-weather-forecasting-app/ I created the project with

lein new figwheel cljs-weather -- --reagent
added the code and dependencies, and then ran
yarn
then opened the project in emacs, where I ran
cider-jack-in-clj&cljs
and the project opened in my browser. I can evaluate simple forms in core.cljs like (+ 1 1) with cider-eval-defun-at-point but trying to evaluate the ns form or, trying to get data from the web with (GET <some url>) causes me to get
Caused by java.lang.RuntimeException
   Unable to resolve symbol: GET in this context
so, what do I have to do to be able to evaluate forms in my buffer as with clj in a cljs project?

bozhidar09:06:37

@patrickanium I guess you forgot to load the buffer first (`C-c C-k`) and your requires are not in scope.

Jim Newton13:06:17

I've defined a record named Foo with a print-method and in the cider repl, it seems to ignore my print-method . Is that normal? My emacs value of cider-print-fn is pprint and I have not set this value anywhere. Its the value out-of-the-box as far as I know.

Jim Newton13:06:07

At the moment I don't know if it is a Clojure bug, or a cider but, or a Jim bug.

Jim Newton13:06:54

clojure-rte.core> (defrecord Foo [x])
clojure_rte.core.Foo
clojure-rte.core> (map->Foo {:x 100})
{:x 100}
clojure-rte.core> (defmethod print-method 'Foo [v w]  (.write w (format "#<Foo x=%s>" (:x v))))
#multifn[print-method 0x7665aecc]
clojure-rte.core> 
{:x 100}
clojure-rte.core> (pprint (map->Foo {:x 100}))
{:x 100}
nil
clojure-rte.core> (print (map->Foo {:x 100}))
#<Foo x=100>nil

dpsutton14:06:32

If you do these steps in a simple “clj” repl is the behavior the same?

Jim Newton14:06:20

you mean cli from the shell command line?

Jim Newton14:06:51

from the clj repl it seems to work.

user=> (defrecord Foo [x])
user=> (defrecord Foo [x])
user.Foo
user=> (defmethod print-method 'Foo [v w]  (.write w (format "#<Foo x=%s>" (:x v))))
user=> (defmethod print-method 'Foo [v w]  (.write w (format "#<Foo x=%s>" (:x v))))
#object[clojure.lang.MultiFn 0x61e3cf4d "clojure.lang.MultiFn@61e3cf4d"]
user=> (map->Foo {:x 100})
user=> (map->Foo {:x 100})
#user.Foo{:x 100}
user=> 

Jim Newton14:06:20

if I change the emacs variable

(setq cider-repl-use-pretty-printing nil)
then the repl prints using my print-method ... this seems to indicate a bug in the cider-pprint-fn implementation, that it neglects to take print-method into account. right?

zilti13:06:05

Ah nevermind, it was my own user.clj causing the issue... But anyway, CIDER is still broken with the most recent shadow-cljs ("missing instance")

bozhidar16:06:21

See https://github.com/rksm/clj-suitable/issues/15 Best you can do is to downgrade shadow for now.

zilti16:06:00

Oh... thanks!

thheller19:06:05

that has nothing to do with missing instance.

thheller19:06:26

missing instance means shadow-cljs is not started in the process you are connected to. so maybe just connected to wrong nrepl server?

zilti09:06:10

I did a jack-in, not a connect. Seems like it is the issue that's also open about cider not working when shadow uses deps.clj for dependencies.

thheller09:06:56

this just means you need to start shadow-cljs before using it ...

thheller09:06:29

(require 'shadow.cljs.devtools.server) (shadow.cljs.devtools.server/start!)

thheller09:06:22

no clue if cider is supposed to do that on its own at some point or what jack-in does exactly

zilti09:06:43

Yes, jack-in is supposed to start the nrepl server, be that via CLI tools, Leiningen, Boot, or Shadow.

thheller10:06:29

nrepl server yes but that has nothing to do with shadow-cljs

thheller10:06:16

but I don't know anything about cider ... I'm just telling you that if you get a missing instance then the shadow-cljs server is not started. whether it is your job to start it or ciders I don't know.

David Pham03:06:16

@bozhidar can we have a flag to remove clj-suitable while it is not working with shadow-CLJS?

bozhidar08:06:51

This will require a new release of CIDER and cider-nrepl, as we’ll need to dynamically load clj-suitable for this to work. There’s already a flag that disables suitable even today, but the current problem happens at load time and the flag doesn’t help with it.

bozhidar08:06:59

I can look into this later today or tomorrow if there’s no fix for suitable by then.

Joshua Suskalo14:06:58

@dpsutton Thanks for the tip! Just implementing a basic implementation of IPending fixes the issue.

cider 4
iperdomo16:06:04

Hi all, lein 2.9.3 depends on nREPL 0.6.0 (https://github.com/technomancy/leiningen/blob/2.9.3/project.clj#L21) and the most recent version of cider-nrepl v0.25.2 depends on nREPL 0.7.0 (https://github.com/clojure-emacs/cider-nrepl/blob/v0.25.2/project.clj#L7) ... how I can deal with this conflict if my project.clj defines :pedantic? :abort ?

bozhidar16:06:52

You’re at the right place. 🙂

Parenoid17:06:18

@bozhidar how do I get the requires in scope?

Parenoid17:06:17

I loaded the buffer with C-c C-k but it errors on the first form (the ns one with the require).

Parenoid17:06:22

whoa... just changed to clojurescript-mode (M-x clojurescript-mode) and it works!

Parenoid17:06:57

thanks for the help 🙂