Fork me on GitHub
#clojure
<
2019-05-03
>
Ivan Koz00:05:20

lets vote what to read next joy of clojure 2nd or programming clojure 3rd ed?

1️⃣ 8
2️⃣ 8
seancorfield00:05:06

I voted for JoC, assuming you haven't read earlier editions of either.

Ivan Koz00:05:25

right, i didn't

seancorfield00:05:42

JoC 1ed was my first Clojure book (but I had Lisp/FP background). Clojure in Action 1ed was my second Clojure book.

Ivan Koz00:05:30

i have java(2 years) and common lisp(3 months + PCL book), 4 months of clojure background

seancorfield00:05:49

Back then, there weren't too many options 🙂 I loved Clojure Programming when that came out. Since then I've bought almost everything except Living Clojure and a bunch of the somewhat random Packt Publishing Clojure books (variable quality!).

seancorfield00:05:09

You'll love JoC then!

seancorfield00:05:35

And then maybe Clojure Applied? Or Programming Clojure 3ed.

Ivan Koz00:05:40

or both :hugging_face:

seancorfield00:05:34

Getting Clojure is an interesting read to.

seancorfield00:05:27

Clojure Cookbook too, although it's getting a bit long in the tooth (maybe there's a 2ed planned/in the works?).

seancorfield00:05:45

Oh, apparently I do have Living Clojure. It just isn't inside a folder like all my other O'Reilly books...

Ivan Koz00:05:57

you sort by publisher?

Ivan Koz00:05:04

i prefer by language \ field

seancorfield00:05:19

Several publisher auto-sync to Dropbox, so those are by publisher. That way I can read the PDFs on any device.

seancorfield00:05:54

So I have 82 tech books by Pragmatic, O'Reilly, and Manning. And then maybe another 50 or so ebooks from other publishers.

seancorfield00:05:33

(My OneDrive a/c has 127 PDFs but that includes technical papers, book previews, reference cards, and a variety of other non-tech-book things so it's hard to be sure)

Ivan Koz00:05:48

thats so cool, i dont have that much money yet 😃 nor time

seancorfield00:05:51

Mostly time. I've been accruing tech books for decades.

seancorfield00:05:24

Several publishers let you "register" your physical copy of a paper book and then you can d/l the ebook for it. But I still have a pretty massive paper library from early decades. Including classics like "A Microprogrammed Implementation of APL" and "Programming the 6502" 🙂

Ivan Koz00:05:38

thats really smart move

Ivan Koz00:05:17

@seancorfield how fast do you read technical books? Like about something new.

seancorfield00:05:44

I'm a speed reader so, very fast...

Ivan Koz00:05:57

I mean it takes me few days per chapter including practice, exaples and side sources like articles on the topic.

seancorfield00:05:23

If I'm practicing alongside, that slows me down a bit. I think I got through Seven Languages in Seven Weeks, including all the exercises in less than 30 hours total. Maybe even close to half that? Can't remember.

Ivan Koz00:05:36

So yeah, i'm about 5 times slower than that.

seancorfield00:05:30

On average, I read about a page a minute. Seven Languages is just over 300 pages. Yeah, I must have gotten through that in a lot less than 30 hours, even with exercises 😐 It's kind of a weird "skill". I was tested in kindergarten and they figured out I have some sort of semi-eidetic memory which means I don't read linearly -- I sort of "snapshot" blocks of text etc and then my brain somehow decodes them asynchronously.

Ivan Koz00:05:58

or it's a magic and you are a wizard

4
Ivan Koz00:05:33

alright thank you Sean, time to enjoy the joy of clojure

sofra05:05:28

Hi all, I am hitting a weird issue with core.spec when trying to add extra assertions to a s/keys spec using s/and. I have been able to make a minimal example of the problem.

(s/def ::bar (s/or :string string?
                   :int int?))
(s/def ::foo (s/and (s/keys :req-un [::bar])
                    (fn [x]
                      (prn x)
                      true)))

(s/explain ::foo {:bar "bar"})
;;=> {:bar [:string "bar"]}
;;=> Success!

(s/explain ::foo {:bar 1})
;;=> {:bar [:int 1]}
;;=> Success!
You can see that the predicate after the s/keys spec now has the :bar value transformed to a pair by the ::bar s/or spec. This is not what I expected.

seancorfield05:05:19

@sofra That's how s/or works.

seancorfield05:05:56

It conforms the value into a data structure that shows how it matched the spec.

sofra05:05:33

thanks @seancorfield I sort of understood that, I didn’t realise it got conformed and passed the conformed value through each predicate in the s/and.

seancorfield05:05:34

user=> (require '[clojure.spec.alpha :as s])
nil
user=> (s/def ::bar (s/or :string string? :int int?))
:user/bar
user=> (s/conform ::bar 42)
[:int 42]
user=> (s/conform ::bar "42")
[:string "42"]
user=>                  

seancorfield05:05:09

Yes, s/and flows values through so if something conforms a value, that is what's passed on to the next predicate.

sofra05:05:39

ahhh, ok thanks I didn’t understand that part. Thanks!

tomaas08:05:00

hi, i can't see how read-string can possibly execute code without using the eval. (read-string "(+ 1 1)") evals to a list (+ 1 1). "(+ 1 1)" is the user input.

tomaas08:05:29

(read-string "#=(+ 2 3)") => 5

tomaas08:05:08

could someone explain how this gets evaluated?

tomaas08:05:06

@mhuebert thanks. read-string is called at runtime parse the this string and return a reader macro expresion. But arent macros expanded at compile time? I dont get how that parsed expression gets run

mhuebert08:05:03

@tomaas reader macros aren’t the same as macros, they are handled at read-time

tomaas08:05:51

how many phases does the 'runtime' compile executable have then? read-time + eval-time?

mhuebert08:05:44

well, if you have eval then you have all the phases, no?

mhuebert08:05:34

> the dynamic and interactive nature of Clojure that means you can invoke the compiler at run-time if you want to. This is all part of the Lisp “code is data” tradition.

tomaas09:05:12

thank you @mhuebert i think i figured it out my doubt

4
roti09:05:53

is there a way to use a leiningen profile in a macro?

tomaas09:05:21

is there some doall + map macro? Similar to run!, but the return the collection?

valtteri09:05:08

What are you trying to do?

tomaas09:05:07

(doall (map #(..) col))

tomaas09:05:36

if i didn't need the result, i could do (run! #(...) col)) which is nicer

tomaas09:05:48

im looking if there is something similar

valtteri09:05:28

One way is to use mapv instead of map. It’s eager. Another is to use transducer version (into [] (map #(...)) coll)

✔️ 8
valtteri09:05:03

Third would be to use reduce instead of map.

mloughlin09:05:33

last time someone asked a similar question, I think the most Clojure-y answer was to use a transducer

valtteri09:05:56

Heh, tried this out of curiosity and it works. You can use normal function composition.

user> (def doall-map (comp doall map))
#'user/doall-map
user> (doall-map #(or (println %) %) [1 2 3])
1
2
3
(1 2 3)

valtteri10:05:51

This might have some serious caveats though, I’m not sure. Personally I like the transducer version most.

valtteri10:05:02

Depending on the situation of course.

duncanmak23:05:09

Hello, I’m used to the cond from Scheme, does the cond in Clojure support the => syntax?

seancorfield23:05:59

@duncanmak I'm not familiar enough with Scheme to know what that syntax means -- could you explain?

duncanmak23:05:21

like, in Scheme: (cond ((re-match ...) => (lambda (match) ...))) if-let feels a bit like it, but it only allow one test

seancorfield23:05:55

Ah, take a look at condp and see if that's closer to what you're looking for...

duncanmak23:05:56

I found https://github.com/Engelberg/better-cond, but I don’t wanna take on a library

duncanmak23:05:55

yeah, i was looking at condp, but it doesn’t seem to capture the result from the test

seancorfield23:05:20

are you sure? its result-fn, which must be a unary function, is called with the result of the predicate as its argument

duncanmak23:05:08

i want to access the result in the consequent part

seancorfield23:05:30

(condp = 4
  2 :>> #(println '2 %)
  4 :>> #(println '4 %))
prints 4 true

👏 4
seancorfield23:05:48

BTW, it's better not to post the same question in multiple channels -- so folks in one channel don't have to spend time answering something that was already answered elsewhere.

seancorfield23:05:10

@duncanmak Did condp solve your needs?

duncanmak23:05:30

i’m gonna give it a try, thanks!