This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-19
Channels
- # announcements (1)
- # beginners (115)
- # calva (7)
- # cider (8)
- # clj-kondo (3)
- # cljdoc (12)
- # clojure (50)
- # clojure-europe (4)
- # clojure-italy (5)
- # clojure-nl (6)
- # clojure-spec (70)
- # clojure-uk (88)
- # clojurescript (54)
- # core-async (16)
- # cursive (5)
- # datomic (31)
- # editors (4)
- # emacs (4)
- # fulcro (29)
- # graphql (17)
- # luminus (1)
- # lumo (2)
- # off-topic (37)
- # pathom (16)
- # random (2)
- # re-frame (5)
- # reitit (3)
- # rum (2)
- # shadow-cljs (192)
- # sql (11)
Is there a succinct way of reducing an array of maps into a single map where all the values of the maps are summed?
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.
You can redirect stdout I believe by binding https://clojuredocs.org/clojure.core/*out*
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?
Well...it 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 😩
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?
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.
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.
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.
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
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
Thanks @U05509S91 and @U051SS2EU - I’m working on the getting it going and these suggestions lead me to good resources for sure 👍
@UMWP0394J http://ohokgotit.blogspot.com/2013/05/debugging-running-clojure-application.html
what’s the idiomatic way of taking a bunch of expressions that might be nil, and getting a list of only non-nils?
(defn foo [thing & others]
(prn thing)
(when (seq others)
(prn others)))
(foo 1 (when false 2))
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
=> nil
(defn foo [thing & others]
(prn thing)
(when (seq others)
(prn others)))
=> #'fy.repl/foo
(foo 1 nil)
1
(nil)
=> nil
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?a compojure "route" is actually just a handler function that returns nil if it doesn't match
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?
(btw, I'm glad to have joined this community... I can't wait to start contributing code and answers. Thanks in advance!)
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
Ok, I understand it more now
#js {}
also is a Javascript interop to say its a javascript object not a clojure one.
But those can't be used like cljs maps right?
sorry, i'm talking about #object [...]
I know about js->clj
and clj->js
, that's a little clearer
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"
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 ...]
And there is no other (practical) difference
Does this ring true?
last question, if I can bother you two minutes longer:
if I have a JS object obj
, I can access its property name
as obj.name
... 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 cljs.user.obj.name
)
That's a particular CLJS syntax right? not a reader macro
OHH I see now
makes perfect sense
damn, how did I miss that in the cheatsheet
OK, thanks folks!
error as in first blok*
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?
reason i'm asking is because the docs say the resulting class might be "anonymous"
https://clojure.org/reference/java_interop#_implementing_interfaces_and_extending_classes
if it's anonymous, and a foreign java library is expecting a class that implements a given interface, will that work out?
yes, you could do this with deftype (would probably want to use the :load-ns
option in deftype too)
deftype will generate a known class, not an anonymous one
I guess, also via gen-class
thank you, @alexmiller!