Fork me on GitHub
Mario C.05:09:12

Is there a succinct way of reducing an array of maps into a single map where all the values of the maps are summed?

Mario C.05:09:46

[{:a 1} {:a 1} {:a 1}] -> {:a 3}

Mario C.05:09:31

merge-with seems like it will do the trick


So, after a bunch of searching I still can’t figure out where standard out ends up. I’m doing a small web app thing with Lein, Ring, Compojure, Hiccup. Not sure how to track it - does Lein or Ring configure it? I’m trying to do the old print statements in my handlers.

Lennart Buit06:09:37

You can redirect stdout I believe by binding*out*

Lennart Buit06:09:43

so maybe any of those libraries do?


@mattias504 and just (prn “hi”) doesn’t end up in the lein repl out? How are you starting your repl?

Mattias06:09:48 turns out, I should have kept quiet a while longer. Thanks for replying, but this was, of course, just another case of... programmer error. Turns out, even with few lines of code confusion can arise. What can I say, years of compilers complaining of types has made me weak 😩

parens 4
Noor Afshan Fathima07:09:03

Hey, I am a beginner in clojure. Have worked on one simple project. Can someone let me know what possible questions can a beginner be asked during a clojure interview?


#jobs-discuss might be a good place for that.

👍 4
Abhinav Sharma11:09:46

Guys, how do we assign the value returned by a go block to a variable?


you need to receive it on a channel and bind it, either by swapping it to an atom or receiving in a let binding.


<!! will let you do a blocking receive on the channel returned by the go block


though I might consider just using an output channel you can pass around to that go block function, and use the return channels more for synchronization.


(let [x (<!! (go [] (Thread/sleep 1000) (+ 1 2)))] x) => 3


just as a quick and dirty example.


though that is still a blocking receive, so all you've done is blocked that let statement until the go form sends the return value through the channel.

Abhinav Sharma13:09:03

Thanks @U05509S91! But how to do this in ClojureScript which has no <!!


that's correct, you can't block in clojurescript. 🙂 you'll need to pass in a channel and maybe use promises, so check out promesa

Abhinav Sharma14:09:35

Ahh, I see - thanks @U05509S91 👍


another option here is take! which is async, and has an optional callback arg to be invoked when the value comes in

Abhinav Sharma12:09:53

Thanks @U05509S91 and @U051SS2EU - I’m working on the getting it going and these suggestions lead me to good resources for sure 👍


how to start a Leiningen process in debug JVM mode?


what’s the idiomatic way of taking a bunch of expressions that might be nil, and getting a list of only non-nils?


(list 1 (when false :foo)) => (1 nil)


for example, this is a bit annoying


I know i could filter, but.. bit icky


(remove nil? coll) doesn't work for you?


not following the ickiness i guess


comes from doing some reagent work


but - yes


(defn foo [thing & others]
  (prn thing)
  (when (seq others)
    (prn others)))

(foo 1 (when false 2))


what's the problem you're solving?


I have a reagent component that can take children


however, some children are conditionally present


the first one is always there


i think reagent is good at throwing nil children out of the render tree


seq not so much


and i want to perform logic based on whether we have [first-el & rest-children]


but, rest-children with conditional args as above is always either (nil) or a value


you could just (defn foo [components] (when (next components) ...))


  (when condition


is it just two items?


not necessarily


in this case, yes


if there’s more it’s interesting too


i could just destructure


@dpsutton (when (next rest-children) ...) was a great suggestion


calling next on rest-children sounds like a bug. Since (next [:a]) returns nil, your rest-children could have valid values and not render in that way.


It sounds like you're got some confusing logic somewhere. I imagine there's a way out of this


yeah! i misunderstood


actually wanted first


but that’s the same area, this helped


thank you


i'm not seeing how you get (nil)


(defn f [x & m]
  [x m])
duplicates> (f 1)
[1 nil]


=> nil
(defn foo [thing & others]
  (prn thing)
  (when (seq others)
    (prn others)))
=> #'fy.repl/foo
(foo 1 nil)
=> nil


well you're calling it with nil. you're sending it a value


(defn foo [el1 & others]
  (if (first others)


ended up with this


thanks though, that was helpful


For compojure routing...


There must be something to the ordering of entries


(GET "/S:section&L:lesson&P:part" [section lesson part])
  (GET "/S:section&L:lesson" [section lesson])
  (GET "/S:section&L:lesson&:drill" [section lesson pre-strdrill])
i'm not able to access /S1&L1&particle like I expect with that last line, moving it to the top doesn't catch the pattern any longer either it seems... any help?


routes are tried in order from top to bottom


a compojure "route" is actually just a handler function that returns nil if it doesn't match


your middle route there will capture everything after L and bind it to lesson

😮 4
Sebastiano Barrera20:09:08

On ClojureScript specifically: can anybody briefly explain what is the semantics of #object[Constructor ...] compared to #js ... ? Like, can an #object[...] (btw, is it called a native object?) be used like a map or vector? How does one work with it in cljs?

Sebastiano Barrera20:09:44

(btw, I'm glad to have joined this community... I can't wait to start contributing code and answers. Thanks in advance!)


It is just the default way things print


If the printing system (which is a little different in cljs from clojure, so I don't know the specifics) doesn't have a rule like "print seqs as ( then coma separated values then )" that matches when asked to print some random thing, it prints them like that


it used to be the case that those would print as #<...> which was sometimes referred to as unreadable objects, but there were changed to print that way which matches up more with the tagged literal syntax, which you can fiddle with to read those objects (but good luck reading that getting the "original" object back), so you can't really call them unreadable objects any more

Sebastiano Barrera20:09:14

Ok, I understand it more now


#js {} also is a Javascript interop to say its a javascript object not a clojure one.

Sebastiano Barrera20:09:35

But those can't be used like cljs maps right?

Sebastiano Barrera20:09:50

sorry, i'm talking about #object [...]

Sebastiano Barrera21:09:08

I know about js->clj and clj->js, that's a little clearer

Sebastiano Barrera21:09:30

they convert into one another... but there's nothing like object->clj, right?


#object [] doesn't tell you anything about the object except that there is no custom printer defined for it


The #object I've always thought was a js object. So you had to use the js interops like (.func Obj_name)


But I think his answer is better.


so you cannot use it to answer any question about the object except "does this have a custom printer defined for it"

Sebastiano Barrera21:09:15

Ok... So, if I understand correctly, a JS object is printed as #js ... if its prototype is Object, while objects from other constructor are printed as #object [Constructor ...]

Sebastiano Barrera21:09:23

And there is no other (practical) difference

Sebastiano Barrera21:09:28

Does this ring true?

Sebastiano Barrera21:09:45

last question, if I can bother you two minutes longer:

Sebastiano Barrera21:09:26

if I have a JS object obj, I can access its property name as CLJS-side, it looks like #object [Person ... ] but how do I get its name? (.name obj) doesn't seem to work (it looks for a function named


(.-name obj)

👍 4
Sebastiano Barrera21:09:31

That's a particular CLJS syntax right? not a reader macro

dpsutton21:09:51 check out interop section

👀 4

(.foo obj) calls a method called foo. It compiles to:

Sebastiano Barrera21:09:25

makes perfect sense


(.-foo obj) accesses the property foo. it compiles to:

Sebastiano Barrera21:09:11

damn, how did I miss that in the cheatsheet


error as in first blok*

Michael Stokley21:09:52

can I use clojure to implement a java interface, then generate a jar, then have a foreign java library use that jar, as a kind of plugin?

Michael Stokley21:09:10

reason i'm asking is because the docs say the resulting class might be "anonymous"

Michael Stokley21:09:44

if it's anonymous, and a foreign java library is expecting a class that implements a given interface, will that work out?

Alex Miller (Clojure team)22:09:24

yes, you could do this with deftype (would probably want to use the :load-ns option in deftype too)

Alex Miller (Clojure team)22:09:32

deftype will generate a known class, not an anonymous one

Alex Miller (Clojure team)22:09:40

I guess, also via gen-class