Fork me on GitHub
#cider
<
2020-06-09
>
suskeyhose00: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.

suskeyhose01:06:25

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

suskeyhose01: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.

suskeyhose14:06:58

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

cider 1
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 🙂