Fork me on GitHub
#clojure-uk
<
2021-04-19
>
djm05:04:03

👋

dharrigan06:04:58

Good Morning!

Gulli08:04:47

Mórning

dharrigan08:04:54

I was a bit surprised to learn that destructuring a map, that has a nil, using either when-some or when-let doesn't do what I thought it might do

dharrigan08:04:25

(def config {:foo {:bar nil}})

(when-some [{{:keys [bar]} :foo} config]
  (format "This is %s" bar)) ;; "This is null"

dharrigan08:04:06

The doc's say that when-some will only evaluate the body if the test is not nil.

mccraigmccraig08:04:08

the test is the whole bound value @dharrigan, not something destructured out of it - and config is not nil

dharrigan08:04:36

that makes sense, yup. still, had to learn that 🙂

dharrigan08:04:06

so is there a better way of writing this so that if "bar" is nil, then not to execute the body?

dharrigan08:04:28

I was thinking of just testing again i.e., a nested (when bar ,,,,,)

mccraigmccraig08:04:31

that's what i would do

dharrigan08:04:41

:thumbsup: that's what I did 🙂

folcon08:04:57

Have people seen this by any chance? https://github.com/IGJoshua/farolero

dharrigan08:04:15

I was reading about it this weekend, prompted by the blog posting

folcon08:04:11

I've not used CL style exceptions much, but they seem handy, I'm assuming they handle normal js / java exceptions as well, would be cool to see some more interesting things happening here 😃...

folcon08:04:46

Can you link the blog post? I don't think I've seen it...

dharrigan08:04:45

My current understanding, and I believe something the blog author also comments upon, is that because (at least on the JVM) Clojure, being a hosted language, the normal paradigms of try, catch and if-some (and the ilk) are very common, then it may feel a bit unnatural

dharrigan08:04:30

I'm not sure tbh, I will definitely need to spend some more time experimenting and learning to see if it works for me 😉

dharrigan08:04:05

Here's the blog post btw:

folcon08:04:06

Thanks 😃... I mean I'm hoping it will allow for more flexibility in dealing with exceptions...

dharrigan08:04:00

Yes, agreed. I am eager to delve further into it and see if can help my applications 🙂

dharrigan20:04:21

If I recall, someone here got the "Software Design for Flexibility" book by Chris Hanson and Gerald Jay Sussman

rickmoynihan07:04:55

It’s good. I’ve only read the first two or three chapters so far. I’m not sure for many people the name reflects the contents. It’s more of a fugue on compositional systems. Obviously composition is a way to build flexible software, but in places it is a bit detached from practical applications typical developers face. That’s not to say that it’s not practical, just that things like the combinator system in chapter 1 aren’t really presented as a solution to a real world problem. It’s not really contrasted to the alternative, and iirc there’s no final program built from the combinators they make which was a little disappointing. Being a long time fan of Sussman though the contents are exactly what I was expecting, and why I bought it, so no real complaints from me.

dharrigan08:04:05

Thanks for the mini-review!

dharrigan20:04:35

Interested to hear a quick opinion on it 🙂