Fork me on GitHub
#beginners
<
2020-06-22
>
bartuka00:06:19

ahn, it is possible to add the implementation using extend

(extend Value
  IMyInterface
  {:isEmpty (fn [this] "ok")})

bartuka00:06:34

both .isEmpty and isEmpty are available.

dpsutton00:06:59

Awesome. Thanks

baibhavbista06:06:51

Hello guys, I wrote a beginner-friendly walkthrough for getting a Clojure environment setup on Windows. Would love feedback, especially from learners who go through this to get their environment set up. https://www.notion.so/baibhavbista/Beginner-Clojure-Environment-Setup-Windows-36f70c16b9a7420da3cd797a3eb712fa

littleli11:06:03

I quite like it. I'll give it a go once I'm on my Windows box. Btw do you mind if I take it as an inspiration to write similar guide but without WSL?

👍 3
baibhavbista06:06:28

If you have any suggestions, feel free to comment in the doc itself or message me

bnstvn07:06:01

is there a common pattern for dealing with legitimate nil return values, which might mean error in a context? i found myself writing these quite often, but seems awkward (if-let [ret (fn-with-legitimate-nil)] ret (throw (ex-info "too bad" {:type :mine})))

leonoel07:06:53

(doto (fn-with-legitimate-nil) (assert "too bad"))

leonoel07:06:15

(doto (fn-with-legitimate-nil)
  (when-not (throw (ex-info "too bad" {:type :mine}))))

bnstvn08:06:31

thank you! would you say is this “idiomatic” even there is no interop?

leonoel08:06:11

doto is a good fit when the return value is ignored, not only for interop

leonoel08:06:06

I'm not sure this pattern is idiomatic, but it's rather popular

👍 3
Timur Latypoff07:06:02

Funny thing I noticed, for simple cases (for ...) is faster than (map ...).

(time (when-let [x (into [] (for [i (range 20000000)] (* i 2)))] (count x)))
"Elapsed time: 1716.010281 msecs"
=> 20000000
(time (when-let [x (into [] (map #(* % 2) (range 20000000)))] (count x)))
"Elapsed time: 2346.677037 msecs"
=> 20000000
(time (when-let [x (mapv #(* % 2) (range 20000000))] (count x)))
"Elapsed time: 1367.96382 msecs"
=> 20000000
So looks like it's both more legible (for newbies like me) and faster than intricate map/`filter` combinations 🙂

Vincent Cantin14:06:49

it will be faster with a transducer

Matheus Moreira07:06:45

hello, all! i am reading about transducers (https://bit.ly/3hPXdqk and https://bit.ly/2Ynwkm4) and i’d like to confirm something: when i comp transducers is it correct to say that the operations are applied in the inverse order we usually have resulting from comp? e.g. if i (comp str +) then + comes before str but if i (comp (map inc) (filter odd?)) then inc happens before odd?.

Vincent Cantin14:06:58

if you are interested, there are other articles about transducers at https://vincent.404.taipei

David Pham07:06:26

Yes. You can think of comp as -> for transducers

👍 3
David Pham07:06:08

The reason is a (map inc) returns a transducer. I would recommend watching the transducers talk from Rich Hickey from strangeloop to understand why.

👍 3
David Pham07:06:28

In short: (map inc) returns a function which accept another function as input, but the process is done the inverse order. (You could make an analogue with middlewares if that helps).

Matheus Moreira07:06:40

cool, thanks! i was having a hard time trying to understand the texts because the results usually were different from my mental calculations. today i took some time to textually expand the composition and see what was going on and then wanted to confirm that it was indeed the -> order instead of the usually expected comp order. 🙂

jaihindhreddy11:06:14

If we're a little pedantic (sorry 😅), comp works normally with transducers. Think middleware that transform HTTP request handlers. IF you take two of these A and B, comp them and then transform a handler with that and use it. B will be passed the handler, and the returned handler will be passed to A, which itself returns a handler, which is used. Now, if both A and B are middleware that add headers a and b respectively, then when a request comes in, header a gets added first and then b gets added. Hope this helps.

Matheus Moreira07:06:51

i’ll check the talk.

David Pham08:06:44

You might to watch the Clojure reducers talk as well (the one where he talks about apple pies). Which is a bit of the foundation I heard.

👍 3
Mark-James M.19:06:36

Is there a reason why you do (conj a-vector value) but (cons value a-vector)? To preserve the order?

andy.fingerhut19:06:25

I do not know if the answer to that particular question can be found at this FAQ on argument order in Clojure core functions, but probably worth reading: https://clojure.org/guides/faq#arg_order

👍 3
andy.fingerhut19:06:27

For cons , the Scheme/Common Lisp function of the same name may have been an influence on arg order there.

noisesmith19:06:31

yeah, that's my first hunch as well

seancorfield20:06:06

conj is a collection function and adds a value at the "appropriate" (fast) place for the specific collection type. cons is a sequence function and always adds a value at the start of the sequence (which is always O(1)).

👍 3
seancorfield20:06:12

(conj [1 2 3] 4) produces a vector. (cons 1 [2 3 4]) produces a sequence (technically a Cons cell with 1 as the first element and (seq [2 3 4]) as the rest of the elements).

sroller20:06:23

is seesaw still a lib which should be used today? I'm trying to go with a tutorial and ran into: "Tried to use insecure HTTP repository without TLS:" while running Leiningen to fetch the dependencies.

noisesmith21:06:44

you shouldn't need any non-default repositories to use seesaw

seancorfield21:06:36

@sroller What does lein version report? Wondering if you have an old version of Leiningen that's still using http links...

sroller22:06:34

Leiningen 2.9.3 on Java 13.0.1 OpenJDK 64-Bit Server VM I read I should downgrade to 2.9.1 which wouldn't be as "picky" with http/https.

sroller22:06:31

Ha, I switched to seesaw 1.5.0 and the problem went away.

3
sova-soars-the-sora22:06:54

I'm using memoize ... but I get clojure.core$memoize$fn__6877@7f3d28c0 instead of a result

sova-soars-the-sora22:06:35

ohhh oh oh oh just DEF not DEFN

parrot 3