This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-23
Channels
- # beginners (81)
- # boot (1)
- # cider (1)
- # cljs-dev (15)
- # cljsrn (1)
- # clojure (27)
- # clojure-europe (9)
- # clojure-hamburg (2)
- # clojure-italy (6)
- # clojure-nl (6)
- # clojure-spec (10)
- # clojure-uk (33)
- # clojurescript (9)
- # clojurex (5)
- # cursive (14)
- # datomic (21)
- # devcards (2)
- # duct (72)
- # figwheel (1)
- # fulcro (6)
- # kaocha (3)
- # leiningen (5)
- # nrepl (10)
- # off-topic (65)
- # parinfer (12)
- # re-frame (68)
- # reagent (1)
- # reitit (14)
- # shadow-cljs (65)
- # spacemacs (6)
- # sql (4)
- # tools-deps (2)
- # yada (1)
@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.
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 []
?
(let [result []] result (conj result 2) (if true result)) is giving my a []. In your snippet I think there is a misplaced ]
ah true, my bad!
(let [result []
result (conj result 2)]
(if true result))
should work!@trailcapital that works. Thanks
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?
Generally speaking, a spec says what code should do, a test checks that it does
So I could say that a square
function always returns natural numbers, thats a spec
And then check that, given 3, it will return 9, thats a test
Is there anybody use Carmine for operating Redis? How to iterate over all items in Redis list?
@lennart.buit thank you very much, things make sense now. so that mean i can use both 🙂
Yes, if you write your specs correctly you can generate your tests ^^!
@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.
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?
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"}}}}
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)
@vitorstipanich looks like shadow-cljs is not on your classpath. what did you use to start the JVM?
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
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?
this might also help https://medium.com/@jacekschae/slick-clojure-editor-setup-with-atom-a3c1b528b722
atom is totally fine to use. I personally use Cursive and many other people use emacs
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)))
CompilerException java.lang.ClassCastException: java.util.concurrent.TimeUnit$3 cannot be cast to clojure.lang.IObj
@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
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
@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.
so it becomes
`(.schedule ~pool
(fn [] (~func ~@body))
~time
TimeUnit/MILLISECONDS)
@thheller yeah it should... but it doesnt do anything xD I think I think Im doing something wrong. Im running it with ctrl + r
And how do I change this (fn [] (~func ~@body))
to runnable only, error More than one matching method found
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?
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?
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?
😞 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.
@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.
But good news: benchmarking is super easy in Clojure 🙂 https://github.com/hugoduncan/criterium
YEah… I dunno what you mean by constant-time / linear-time, but I will try the bench, thanks
(this is also what I meant by "asymptotic argument")
@rcustodio do note that they are not interchangeable. Case can only deal with constants, whereas cond can deal with pretty much anything.
Bozhidar Batsov's guide mentions it: https://github.com/bbatsov/clojure-style-guide#case
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.
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.
Hmmm… if its not compile-time, the variable comes from a databse, then case would not be that performatic
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
)
There might be a bigger problem if you're having to do this very often.
Excessive branching is a smell IMHO.