Fork me on GitHub
#clojure
<
2018-07-05
>
orestis07:07:54

I’m trying to setup expound when running a REPL with CIDER. Even when I do the recommended (alter-var-root #'s/*explain-out* (constantly expound/printer)), *cider-error* gives me the original spec error. In the actual repl output, I see the exception as formatted by pretty, but still no expound formatting. Any pointers?

bbrinck09:07:09

Does using set! work? I think the Clojure REPL sets up an outer binding for s/explain-out

bbrinck09:07:02

Sorry for the bad formatting on the code above, I’m on my phone

bbrinck09:07:48

I’ll warn you that expound errors sometimes print weirdly in CIDER due to incompatibilities with new lines. I’ve opened a Github issue in CIDER.

bbrinck10:07:13

FWIW, when using expound for instrumentation, consider using ‘custom-printer’ with “print-specs?” set to false and “show-valid-values?” set to true. The output is little more helpful with those settings.

orestis10:07:40

Thanks — I’ll also ask in #cider — I think I might need to do something more specific there.

bbrinck11:07:52

OK, FWIW, I use expound with CIDER by doing “lein repl” in terminal then “cider-connect” and using “set!” it works for me. But I haven’t tried letting CIDER set up the REPL via “cider-jack-in”

bbrinck11:07:05

Does the project use lein or boot?

orestis12:07:16

Lein via cider-jack-in.

orestis12:07:30

But I’m also using pretty so perhaps the combination messes something up?

bbrinck14:07:14

Hm, I’m AFK so I can’t try ‘cider-jack-in’ here but I can try later. Maybe try with a normal “lein repl” outside of emacs?

bbrinck14:07:33

(Just to isolate the cause)

bbrinck14:07:25

I wouldn’t expect “pretty” to interfere - I’ve used it in projects with expound - but I’ve been wrong before

orestis16:07:54

I’ll have a go tomorrow at the office and report back. Thanks for the help!

bbrinck16:07:32

I created a new project with lein new and then used cider-jack-in. The following worked for me with that REPL:

(require '[expound.alpha :as expound]
         '[clojure.spec.alpha :as s]
         '[clojure.spec.test.alpha :as st])

(set! s/*explain-out* expound/printer)

(st/instrument)

(defn) ; gives expound error

bbrinck16:07:09

(of course, my project.clj needed to be changed to use:

[[org.clojure/clojure "1.9.0"]
 [expound "0.7.1"]]

bbrinck16:07:29

I tried using [io.aviso/pretty "0.1.34"] as well, it still seems to work for me. So I’m unfortunately not sure what’s different. Good luck and let me know if you figure it out 😄 !

orestis16:07:04

Is the call to instrument needed? I’m not doing this.

orestis16:07:45

But it looks like it should work, I’ll give it a try and report back :)

👍 4
orestis07:07:51

OK, I can confirm — using set! works, but alter-var-root doesn’t.

orestis08:07:33

This is even just typing on a lein repl. I’ll file an issue at expound.

bbrinck08:07:53

Sure, that’s fine, although I’m not sure expound can do much here, unless I’m misunderstanding your use case. Perhaps I just need to clarify how to do this in the docs?

bbrinck08:07:51

The README suggests using set! (except in specific cases like a non-REPL environment) but I’m happy to clarify if the instructions were confusing

bbrinck08:07:14

In any case, I’m glad that set! works for you 😄

orestis09:07:38

I’m sure I misunderstand something 😄 I thought alter-var-root should be more generic than set!?

bbrinck10:07:10

IIRC, it depends upon the context, but I’ll double check when I’m at the keyboard 😀

bbrinck10:07:15

Do try a custom-printer with the options I mentioned above and let me know if you have any trouble. I think it makes the output much more readable for instrumentation

bbrinck15:07:50

I did some experiments with the REPL. Keep in mind that at the REPL, all code is run within a top-level binding call that sets up default values for s/*explain-out*: https://github.com/clojure/clojure/blob/2a08ef40018f1b504602545603eec840b05b33b1/src/clj/clojure/main.clj#L85

bbrinck15:07:16

In this context, you can call alter-var-root, but the value set up by binding always takes precedence. Here’s an example with another dynamic var https://gist.github.com/bhb/d82fcf0f80f555c28afa8db320be16c8

orestis15:07:17

Wow, thanks for that — it seems that’s the problem. I’ll do another experiment on Monday to see what actually happens when code running inside a threadpool (e.g. Jetty handlers) encounters a spec error.

bbrinck15:07:35

Cool, let me know what you discover!

bbrinck15:07:14

If something special needs to be done, I’ll add it to the README

orestis15:07:32

Thanks a lot — and I just realised you are bhb 🙂 Thanks for expound, it rocks 🙂

bbrinck15:07:52

You’re welcome!

orestis07:07:26

What I’m trying to do is catch common beginner errors such as (defn foo :bar)

andreasklein09:07:03

Is there a canonical way to edit an xml tree in multiple locations using zippers? I am trying to edit the content of multiple nodes and end up with multiple trees each containing one edit.

andreasklein09:07:15

Can I merge these into XML tree?

stathissideris10:07:17

@andreasklein are you chaining your transformations with ->?

stathissideris10:07:29

or ->>, can’t remember

andreasklein10:07:11

I am using data.zip.xml/xml->

stathissideris10:07:59

sorry, I’ve only used vanilla zippers 🙂

kirill.salykin11:07:32

how I can check if catched exception is ex-info?

mpenet11:07:35

catch clojure.lang.ExceptionInfo

kirill.salykin11:07:14

I have one catched already I just need to interpret in different

mpenet11:07:20

then instance?

kirill.salykin11:07:27

I think if it is not ex-info ex-data just returns nil

kirill.salykin11:07:30

would this work?

kirill.salykin11:07:42

k, thanks for help!

mpenet11:07:10

(instance? clojure.lang.ExceptionInfo (ex-info "" {}) ) true

orestis13:07:07

Is it possible to use Reitit with Pedestal? There are mentions of interceptors in Reitit, but I’m not sure if they are meant to be used by Pedestal or if there is just a similar concept?

ikitommi13:07:52

@orestis Reitit supports both mw & interceptors, but the interceptor-http module is not public yet. Goal is to publish it out after vacations, we could cook up a Pedestal example, as people have been asking for it. There is #reitit too.

orestis13:07:28

Cool, thanks @ikitommi I’ll move to #reitit 🙂

ag22:07:44

I'm feeling a bit stupid, can't figure out how to elegantly traverse vector of maps and make a new map with keys being values of a selected property of each map and number of records... e.g. if I have: [{:type "foo"}, {:type "bar"}, {:type "foo"}, {:type "foo"}] I should get something like: {"foo" 3 "bar" 1}

ag22:07:22

I mean I can probably do it by traversing the coll twice, which doesn't feel to be right

noisesmith22:07:55

(frequencies (map :type coll))

👍 12
4
ag22:07:12

oh... right... I forgot about frequencies thing