This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-26
Channels
- # announcements (6)
- # beginners (88)
- # calva (12)
- # cider (13)
- # cljs-dev (27)
- # cljsrn (2)
- # clojure (68)
- # clojure-argentina (2)
- # clojure-dev (10)
- # clojure-europe (1)
- # clojure-greece (1)
- # clojure-italy (5)
- # clojure-nl (15)
- # clojure-spec (33)
- # clojure-switzerland (1)
- # clojure-uk (10)
- # clojurescript (121)
- # clojutre (3)
- # code-reviews (2)
- # core-async (1)
- # cursive (10)
- # data-science (1)
- # datomic (21)
- # emacs (10)
- # events (1)
- # fulcro (25)
- # graphql (6)
- # joker (4)
- # kaocha (12)
- # lambdaisland (3)
- # music (2)
- # off-topic (112)
- # om (2)
- # re-frame (25)
- # reagent (29)
- # reitit (93)
- # rewrite-clj (2)
- # shadow-cljs (18)
- # slack-help (4)
- # spacemacs (8)
- # tools-deps (1)
- # vim (2)
- # yada (5)
My profiles aren't merging correctly or at all. I can't figure out why. I have {:profiles {:dev [:project/dev :profiles/dev], :profiles/dev {}, :project/dev {:dependencies [["dependencies list here"]]}}}
in my project.clj and have this {:profiles/dev {:env {:happy-hour? true}}}
in my profiles.clj but when the app starts (:happy-hour? env)
returns nil.
You have :profiles/dev {}
in your project.clj
which will override the profiles version
I got rid of it and its still not picking up the env variables. Which is odd since it works fine in another project. Which I am copying the project.clj structure from
dunno... I stopped using leiningen years ago :rolling_on_the_floor_laughing: ¯\(ツ)/¯
Hi guys, has anyone tried solving leetcode
problems in clojurescript
and managed to get the compiled output passing? It seems the solution size limit is <100Kb and often the compiled CLJS output, even with :optimizations :advanced
gives 100Kb size.
Really curious about this 🙂
> Is there a way to evaluate something at the REPL without it affecting *1
et all?
Sorry for the nagging. I don't know how to figure this out. I need something that works for both Clojure and ClojureScript (or if it is two different ways, that'll work as well).
how come you don’t want it to affect *1
et al?
It's for Calva (a Clojure dev environment). It supports to evaluate forms from editor files to the repl prompt. To be nice to the user the form is evaluated in the file's ns and then the repl prompt's ns is restored. It is pretty neat. But a side effect is that *1-3
are affected by the in-ns
evals.
I am developinng an app with clojurescript but I didn't touch clojure at all. I found a nice crawler I tried same way like I would do in CLJS but I can't run it in repl what I am doing wrong?
@m373h4n does this work for you?
(require 'pegasus.foo)
(pegasus.foo/crawl-sp-blog)
user=> (require 'pegasus.foo)
nil
user=> (pegasus.foo/crawl-sp-blog)
CompilerException java.lang.RuntimeException: No such var: pegasus.foo/crawl-sp-blog, compiling:(C:\Users\Root\AppData\Local\Temp\form-init6063905182774601959.clj:1:1)
stop your repl, then do lein repl
again, then
(require 'pegasus.foo)
(pegasus.foo/crawl-sp-blog)
when you used ns
you redefined the namespace to an empty namespace. use in-ns
to avoid that
yeah. I find it much more obvious with in-ns
though, as not even clojure will be there 😛
if you happen to use in-ns
before require
by accident, you can always do (clojure.core/refer-clojure)
to have the core functions available, or just (in-ns 'user)
Anyone could point me how you could adapt the make-component
code in this file (https://gist.github.com/pesterhazy/2a25c82db0519a28e415b40481f84554) following the advice from the official wiki page (https://github.com/clojure/clojurescript/wiki/Working-with-Javascript-classes)?
Basically, how do you extend a JS class in cljs?
I got the solution to my answer: https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#hooks
Just need to know how to google long enough
can anybody please show me a code sample, I'm stuck... given an integer number produce a sequence of its digits (not using string conversions)
I'm not sure exactly what you mean
123 => (1, 2, 3)
is that an example of input/output you are trying to get(loop [num 123
digits '()]
(if (pos? num)
(recur (quot num 10) (conj digits (rem num 10)))
digits))
From what I remember, this problem is generally solved using the modulo operator and a loop to break out the various digit places.
I was thinking of smth like
take-while #(not (zero? %)) (iterate #(somefunc) n)
where somefunc uses quot
/`rem`
https://pragprog.com/book/vmclojeco/clojure-applied is a good one, maybe Joy of Clojure as well?

@U05509S91 yeah, Clojure Applied is an awesome book , haven't read Joy of Clojure, will grab a copy , thanks for the recomendation
But is sad that Clojure Applied doesn't talk abut specs. Would be awesome to have another edition including specs.
It's a good one although it often feels like too abstract (especially chapters 3 and 4 would benefit from having more elaborate examples). I love it but I always feel like it should have been 3-4x longer book 🙂
hi, I'm running into a silly issue that I can't understand,
(#(concat (take (- 1 %2) %1) (nthrest %1 %2)) [1 2 3 4 5 6 7 8] 3)
(4 5 6 7 8)
when running this code the take function returns an empty seq but if I put a value instead of the calculation it workswhy are you passing a negative number to take?
did you reverse the args to -
?
anyway, if you give take a positive arg you'll get a non-empty result
thanks
too much time looking a the same thing
also if you switch nthrest
to drop
, the parallel with take is more obvious, and they can both use their args in the same order
(drop is just flipped nthrest)
ooh cool, I though drop , didn't take an idx
can i use doseq to walk through dictionary entries? i thought recursion would be best but it turns out it's just an xml file one layer deep really
"dictionary entries" are not a Clojure data structure. Are you asking about a Clojure map, or some other Clojure data structure?
doseq
can be used to iterate over any of the fundamental kinds of Clojure collections: sequence, vector, list, map, or set. Note that doseq
is intended for performing side effects in its body, since the doseq
expression itself always returns nil. You may want for
instead, which can return new sequences.
it's a vector
of maps
mm for returns a new sequence... cool
thank you kindly, will investigate
hmmm my for doesn't work?
(for [dk jmdict]
(println (:tag dk))
(println (:content dk)))
where jmdict is a vector coming in
Caused by: clojure.lang.ArityException: Wrong number of args (3) passed to: clojure.core/for
The body of for
must be a single expression. It is used to return a value
@sova for
is lazy -- make sure you are actually consuming all of the result
For println
, which is a side effect, you may want to use doseq
Good point re : single expression!
ohhh o.o could you please elaborate a bit?
The body of your attempted for
consists of two expressions, each a (println ...)
That is one too many, for the body of a for
expression.
Is that what you wanted elaboration on?
ah okay, so it could work if there was only One println
yeah, and for is good for returning a sequence then, like doing a transformation
If you want to take some collection, do some processing on it, and return a value, you may use for
to do that. It returns a sequence, and in the simplest case for
returns a sequence containing one element for each of the input sequence's elements, and that element in the return value is the value of the body of the for
expression.
style-wise, when do you prefer for to doseq?
If you know your goal is only to do some side effecting things, like println
, then doseq
is closer to the intended use.
Ahh that makes a lot of sense, so the body of the for loop will become each individual result in the result vec
I learned today that recursion is so cool and often not the answer! lol
println
always returns nil
. If you use println
as the body of a for
expression, you will get back a return value that is a sequence consisting of one nil
per element of the collection you iterated over (more generally, once for each time for
evaluates its body).
Oh wow, I see
That is often not a useful return value.
Right. Very good to know this distinction
doseq
returns nil
-- so it is only for side-effects; for
is lazy and returns a value (so it should not be used for side effects in general).
Also, as Sean mentioned, for
is lazy, and doseq
is eager.
Ah okay, that's cool to know as well.
Great! I've made a lot of progress thanks to y'all in just a few minutes! Thanks again
@sova Sometimes it's helpful to think of it this way: (for [x coll] (f x))
== (map f coll)
and (doseq [x coll] (f x))
== (run! f coll)
-- that breaks down as soon as you have more than one collection being iterated over but it might be a helpful meme for remembering the basics?

(it's not an exact equivalence but...)
hi, I’m doing exercises at http://4clojure.com and my solution works on the repl but not the site, the problem is reverse interleave, here’s the code
(fn [coll n] (map #(reverse (into () (take-nth n) (drop % coll))) (range n)))
any idea why??nevermind got rid of the into
funny enough, (into () coll)
is a decent way to implement reverse
especially if you also want to transduce while reversing like above