Fork me on GitHub
#beginners
<
2018-11-23
>
rohitvvv00:11:04

@trailcapital Thanks for pitching in. The result still is empty. I am trying to loop over a collection and accumulate the result in a vector. Your code snippet also prints an empty result.

enforser00:11:53

my code snippet definitely returns a value (`[2]`). Can you post more context so I can see why it might be returning empty? or are you just running the snippet and it is empty? is it nil or []?

rohitvvv00:11:41

(let [result []] result (conj result 2) (if true result)) is giving my a []. In your snippet I think there is a misplaced ]

enforser00:11:55

ah true, my bad!

(let [result []
       result (conj result 2)]
  (if true result))
should work!

rohitvvv00:11:56

Happy Thanksgiving

enforser01:11:11

my thanksgiving was back in October (Canada!), but thanks! you too.

Daouda07:11:06

hey guys, i am newbie, getting myself to learn clojure. I need to write test and want to know the difference between clojure.spec and clojure.test?

Lennart Buit08:11:16

Generally speaking, a spec says what code should do, a test checks that it does

Lennart Buit08:11:05

So I could say that a square function always returns natural numbers, thats a spec

🙏 4
Lennart Buit08:11:22

And then check that, given 3, it will return 9, thats a test

stardiviner08:11:14

Is there anybody use Carmine for operating Redis? How to iterate over all items in Redis list?

Daouda08:11:02

@lennart.buit thank you very much, things make sense now. so that mean i can use both 🙂

Lennart Buit08:11:23

Yes, if you write your specs correctly you can generate your tests ^^!

lispyclouds08:11:20

@stardiviner you can use (car/llen) to find the length and (car/lrange start end) to get the values as a clojure list. They you can map over it.

Daouda08:11:23

i need to represent two different entities and considering using map or defrecord. Which one should i pick? Also both are immutable. So how can i am record changes on my entities?

joshkh11:11:03

using deps.edn i'm trying to include a package from maven, and also a classifier from the same package. it looks like including the :classifier key works but doesn't load the main package, and i can't add the dependency twice because deps.edn is a map:

{:deps {
        {remote.package/parser {:mvn/version "1.0.0"}
         remote.package/parser {:mvn/version "1.0.0"
                                :classifier  "additional-package"}}}}

vhead12:11:15

Anyone in here ever had any issues with shadow-cljs? When running (shadow.cljs.devtools.api/nrepl-select :app) I get the following error:

ClassNotFoundException shadow.cljs.devtools.api  java.net.URLClassLoader.findClass (URLClassLoader.java:382)

thheller12:11:30

@vitorstipanich looks like shadow-cljs is not on your classpath. what did you use to start the JVM?

vhead12:11:32

you mean the repl? I'm using the proto-repl on atom

thheller12:11:12

I don't know how proto-repl works but here are some instructions to use it with shadow-cljs https://shadow-cljs.github.io/docs/UsersGuide.html#_proto_repl_atom

vhead12:11:54

I'm definitely gonna check this out (thanks!!). I just choose proto-REPL cause it's my first time on clJS and earlier I was checking a tutorial. What is the most recommended one?

thheller12:11:22

atom is totally fine to use. I personally use Cursive and many other people use emacs

thheller12:11:34

vscode is also ok

rcustodio12:11:32

Good morning

rcustodio12:11:02

Can someone help me with this schedule wrapper, it keeps giving me errors

(defmacro schedule [pool time func & body]
  (let [pool (vary-meta pool assoc :tag `ScheduledExecutorService)
        unit TimeUnit/MILLISECONDS
        unit (vary-meta unit assoc :tag `TimeUnit)]
    `(.schedule ~pool
                (fn [] (~func ~@body))
                ~time
                ~unit)))

rcustodio12:11:38

CompilerException java.lang.ClassCastException: java.util.concurrent.TimeUnit$3 cannot be cast to clojure.lang.IObj

vhead12:11:02

@thheller thats the tutorial I was following earlier. the problem is that he goes with keybinds and is using a mac. Im using a windows lol

thheller12:11:00

I'm on windows too but no idea about atom so no idea what would be different 😛

vhead12:11:36

Yeah I'm already stuck on the step5 of the tutorial lol. It says that I should run an command but it doesnt do anything

vhead12:11:48

I mean the shadowcljs with protorepl one

thheller12:11:59

I think it should show a dialog with host/port inputs?

thheller12:11:44

@rcustodio just emit TimeUnit/MILLISECONDS directly instead of ~unit. can't set metadata on the TimeUnit instance itself. the above vary-meta sets the :tag on the pool symbol only. not the instance.

rcustodio12:11:18

@thheller thanks, and without the ~???

thheller12:11:27

yes without

rcustodio12:11:55

so it becomes

`(.schedule ~pool
                (fn [] (~func ~@body))
                ~time
                TimeUnit/MILLISECONDS)

vhead12:11:41

@thheller yeah it should... but it doesnt do anything xD I think I think Im doing something wrong. Im running it with ctrl + r

thheller12:11:49

ctrl+r doesn't do anything for me? ctrl+shift+p works for me

vhead12:11:20

LOL yeah you're right

rcustodio12:11:44

And how do I change this (fn [] (~func ~@body)) to runnable only, error More than one matching method found

thheller13:11:17

^Runnable (fn ...) should do it

rcustodio13:11:52

Thank you again

rcustodio13:11:58

Now.. I have 2 files, client.clj and client/ping.clj The client needs to call ping/handle and the ping needs to call client/write, BUT it gives me Cyclic load dependency, what is recommended in this cenario?

gklijs16:11:33

I think there are two options, either use yet another namespace, or do something like (declare de-ser-keys) to set the function in the first namespace, and then a defn afther the other namespace is loaded. But maybe there is a better way?

rcustodio17:11:20

Thanks, I had to transfer the “commands” of the client to another file

jumpnbrownweasel16:11:09

I'm trying to come up with a rule to memorize about the use of functions with the word "some" in them, since there are a bunch of them and there is an inconsistency. - some and some-fn define "some" as "at least one result is truthy" (not false or nil, as usual) and you pass a predicate fn to return the result. - all the others (`some?`, if-some, when-some, some->, some->>) define "some" as non-nil (false is considered "something") and you don't pass a predicate fn. Sound right?

lilactown18:11:50

all I know is after reading your post, some no longer looks like a real word 😛

jumpnbrownweasel00:11:22

😞 I guess that doesn't help then. Maybe it is simpler to just say that some and some-fn are exceptions to the rule that "some" means non-nil.

rcustodio17:11:47

Which is more performatic, case or cond?

leonoel18:11:28

case is constant-time, cond is linear-time

val_waeselynck18:11:54

@rcustodio Honestly, I wouldn't even hope to find a general rule for that - there's just too many unpredictable ways both the Clojure Compiler and the JVM could optimize (or not) this stuff. Although cond is supposedly linear time and case supposedly constant-time, you usually won't use them with enough args that you can rely on an asymptotic argument about performance.

val_waeselynck18:11:22

But good news: benchmarking is super easy in Clojure 🙂 https://github.com/hugoduncan/criterium

rcustodio18:11:16

YEah… I dunno what you mean by constant-time / linear-time, but I will try the bench, thanks

val_waeselynck18:11:29

(this is also what I meant by "asymptotic argument")

rcustodio18:11:20

I see, thanks, gonna read about it

orestis18:11:39

@rcustodio do note that they are not interchangeable. Case can only deal with constants, whereas cond can deal with pretty much anything.

rcustodio18:11:42

I have (:x val), in this case the case would be better

rcustodio18:11:45

For what I’m reading

dpsutton18:11:40

check out the docstring for it: >>> Unlike cond and condp, case does a constant-time dispatch, the clauses are not considered sequentially. All manner of constant expressions are acceptable in case, including numbers, strings, symbols, keywords, and (Clojure) composites thereof.

eMko18:11:18

If you have a compile-time constant, you can use case. It wold not only be faster but IMHO you gives an information to the reader that you have a compile time constant.

rcustodio18:11:16

Hmmm… if its not compile-time, the variable comes from a databse, then case would not be that performatic

rcustodio18:11:54

Or the compile-time is the value to test

rcustodio18:11:21

(case (:prefix message)
  nil
  "jtv"
….

rcustodio18:11:48

when test expressions are compile-time constants
yeah, case is better

rcustodio18:11:09

Not better, but more recommended

rcustodio18:11:31

Thanks for all the help

beders23:11:04

Halp! I'm suffering from turkey left-over brain freeze, but isn't there a built-in function for this somewhere:

(if (pred value)
    value
    else-value
    )

enforser23:11:03

there is no core function for what you're doing

👍 4
enforser23:11:09

that I know of, at least

jaihindhreddy-duplicate23:11:53

There might be a bigger problem if you're having to do this very often.

jaihindhreddy-duplicate23:11:29

Excessive branching is a smell IMHO.

beders23:11:56

or would work if I'm only interested in the truthiness of value

beders23:11:24

in this case I'm manipulating hiccup structures, which have an optional second attr-map