Fork me on GitHub
#beginners
<
2019-08-26
>
Mario C.02:08:16

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.

seancorfield02:08:06

You have :profiles/dev {} in your project.clj which will override the profiles version

Mario C.02:08:40

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

seancorfield02:08:46

dunno... I stopped using leiningen years ago :rolling_on_the_floor_laughing: ¯\(ツ)

4
Mario C.02:08:55

oof lol I guess I gotta keep looking

Abhinav Sharma06:08:05

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 🙂

pez06:08:05

> 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).

danielneal16:08:35

how come you don’t want it to affect *1 et al?

pez17:08:55

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.

pez17:08:53

(And the user does not even get to see those evals, so major confusing.)

metehan08:08:52

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?

rpkarlsson08:08:27

@m373h4n does this work for you?

(require 'pegasus.foo)
(pegasus.foo/crawl-sp-blog)

metehan09:08:30

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)

metehan09:08:34

it says like this

metehan09:08:51

i started repl with lein repl maybe this is wrong ?

joelsanchez10:08:14

stop your repl, then do lein repl again, then

(require 'pegasus.foo)
(pegasus.foo/crawl-sp-blog)

joelsanchez10:08:27

when you used ns you redefined the namespace to an empty namespace. use in-ns to avoid that

metehan11:08:59

thank you this time it worked

borkdude13:08:02

in-ns also creates a new ns, use require before in-ns

👍 4
joelsanchez13:08:39

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)

David Pham11:08:52

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)?

David Pham11:08:08

Basically, how do you extend a JS class in cljs?

David Pham12:08:00

Just need to know how to google long enough

Sy Borg15:08:01

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)

enforser15:08:16

I'm not sure exactly what you mean

123 => (1, 2, 3)
is that an example of input/output you are trying to get

Sy Borg15:08:52

yes (probably using `iterate'?)

Crispin15:08:31

(loop [num 123
             digits '()]
        (if (pos? num) 
          (recur (quot num 10) (conj digits (rem num 10)))
          digits))

4
futuro15:08:33

From what I remember, this problem is generally solved using the modulo operator and a loop to break out the various digit places.

Sy Borg15:08:47

I was thinking of smth like take-while #(not (zero? %)) (iterate #(somefunc) n) where somefunc uses quot/`rem`

Ludwig16:08:20

hi guys, is there a book like the clojure version of "Effecive Java" ?

gerred17:08:41

https://pragprog.com/book/vmclojeco/clojure-applied is a good one, maybe Joy of Clojure as well?

metal 4
Ludwig18:08:05

@U05509S91 yeah, Clojure Applied is an awesome book , haven't read Joy of Clojure, will grab a copy , thanks for the recomendation

Jp Soares15:09:54

But is sad that Clojure Applied doesn't talk abut specs. Would be awesome to have another edition including specs.

Ludwig18:08:35

thanks for the recomendation , just bought a copy

jumar07:08:08

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 🙂

gonza-lito17:08:42

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 works

noisesmith17:08:32

why are you passing a negative number to take?

noisesmith17:08:41

did you reverse the args to -?

noisesmith17:08:31

anyway, if you give take a positive arg you'll get a non-empty result

gonza-lito17:08:32

too much time looking a the same thing

dpsutton17:08:44

there's also dec if you want a bit clearer way to write it

noisesmith17:08:40

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

noisesmith17:08:50

(drop is just flipped nthrest)

gonza-lito17:08:31

ooh cool, I though drop , didn't take an idx

sova-soars-the-sora21:08:45

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

andy.fingerhut21:08:52

"dictionary entries" are not a Clojure data structure. Are you asking about a Clojure map, or some other Clojure data structure?

andy.fingerhut21:08:05

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.

🙂 4
sova-soars-the-sora21:08:35

mm for returns a new sequence... cool

sova-soars-the-sora21:08:47

thank you kindly, will investigate

sova-soars-the-sora21:08:58

hmmm my for doesn't work?

sova-soars-the-sora21:08:03

(for [dk jmdict]
	(println (:tag dk))
	(println (:content dk)))

sova-soars-the-sora21:08:19

where jmdict is a vector coming in

sova-soars-the-sora21:08:40

Caused by: clojure.lang.ArityException: Wrong number of args (3) passed to: clojure.core/for

andy.fingerhut21:08:31

The body of for must be a single expression. It is used to return a value

seancorfield21:08:35

@sova for is lazy -- make sure you are actually consuming all of the result

andy.fingerhut21:08:44

For println, which is a side effect, you may want to use doseq

seancorfield21:08:13

Good point re : single expression!

sova-soars-the-sora21:08:30

ohhh o.o could you please elaborate a bit?

andy.fingerhut21:08:01

The body of your attempted for consists of two expressions, each a (println ...)

andy.fingerhut21:08:14

That is one too many, for the body of a for expression.

andy.fingerhut21:08:24

Is that what you wanted elaboration on?

sova-soars-the-sora21:08:29

ah okay, so it could work if there was only One println

sova-soars-the-sora21:08:45

yeah, and for is good for returning a sequence then, like doing a transformation

andy.fingerhut21:08:55

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.

sova-soars-the-sora21:08:11

style-wise, when do you prefer for to doseq?

andy.fingerhut21:08:22

If you know your goal is only to do some side effecting things, like println, then doseq is closer to the intended use.

sova-soars-the-sora21:08:46

Ahh that makes a lot of sense, so the body of the for loop will become each individual result in the result vec

sova-soars-the-sora21:08:25

I learned today that recursion is so cool and often not the answer! lol

andy.fingerhut21:08:30

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).

andy.fingerhut21:08:52

That is often not a useful return value.

sova-soars-the-sora21:08:04

Right. Very good to know this distinction

seancorfield21:08:11

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).

andy.fingerhut21:08:33

Also, as Sean mentioned, for is lazy, and doseq is eager.

sova-soars-the-sora21:08:53

Ah okay, that's cool to know as well.

sova-soars-the-sora21:08:20

Great! I've made a lot of progress thanks to y'all in just a few minutes! Thanks again

seancorfield22:08:18

@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?

4
upside_down_parrot 4
seancorfield22:08:33

(it's not an exact equivalence but...)

gonza-lito23:08:45

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??

gonza-lito23:08:07

nevermind got rid of the into

noisesmith23:08:27

funny enough, (into () coll) is a decent way to implement reverse

noisesmith23:08:49

especially if you also want to transduce while reversing like above