This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-17
Channels
- # announcements (1)
- # babashka (94)
- # beginners (76)
- # calva (24)
- # cider (24)
- # clj-kondo (1)
- # cljs-dev (16)
- # cljsrn (45)
- # clojure (135)
- # clojure-europe (9)
- # clojure-france (5)
- # clojure-germany (2)
- # clojure-italy (12)
- # clojure-losangeles (13)
- # clojure-nl (3)
- # clojure-portugal (54)
- # clojure-uk (20)
- # clojurescript (55)
- # conjure (67)
- # core-async (5)
- # cursive (2)
- # datomic (10)
- # docker (7)
- # duct (22)
- # emacs (16)
- # fulcro (34)
- # graalvm (15)
- # hoplon (1)
- # instaparse (1)
- # jobs-discuss (3)
- # juxt (94)
- # luminus (1)
- # meander (4)
- # off-topic (13)
- # pathom (4)
- # pedestal (1)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (61)
- # spacemacs (17)
- # specter (2)
- # sql (23)
- # xtdb (33)
Hi, I'm using IntelliJ with Cursive and I am getting this error message when I try to run a dummy program I made. This is my error. Cannot execute, please download tools.deps in Settings: Cannot execute, please download tools.deps in Settings
This is my path btw with my clj file being within src C:\Users\Cayendo\Programming\FirstClojureProject\src
FYI if you do not get an answer here, there is a #cursive channel, too.
Do you have the Clojure CLI installed? Else you can download in settings I think. Have not used Cursive but used Idea a lot. If you follow the steps, it will work.
I do have Clojure CLI installed so not sure what else I need to do
I only have a few options of disable and uninstall
There are other options as well of managing repositories and HTTP
This is the path to my Java home variable, Its labeled as JDK Home Path in IntelliJ if that Matters. C:\Program Files\Java\jdk-13.0.2
I have my Clojure CLI Tools located at C:\Program Files\WindowsPowerShell\Modules\ClojureTools
That looks like a PowerShell module. Does the command clojure
and clj
work outside PowerShell?
No it does not
It seems it is possible to use the commands outside powershell like this: https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows#run Is it possible in Cursive to specify which command to run?
You need to follow this guide: https://cursive-ide.com/userguide/deps.html#windows
Thats seems to have fixed my issues. Thanks a lot
how can I get an ordered hashmap? I know I could use tuples but then I need to rewrite all my code where I already use the keys, or I should duplicate the keywords both as keys and values
There's sorted-map as well, that sorts based on some comparator function. For insertion order, there's nothing in core.
If you create the sorted-map from a coll, you could use map-indexed and add an :order to your items
There's also: https://github.com/clj-commons/ordered
Hi, I'm trying to filter some data and only get the entries that are true, finding out if they are true or false is easy enough, like so: (map #(:is_video %) (hot!)) I want to have the actual full entires of the ones that evaluate to true, not just know whether it's true or false, how would I do something like that? I always end up using filter and nested anonymous functions and getting confused
You use filter
. By the way, keywords are functions, so #(map :is_video (hot!))
works. So does (filter :is_video (hot!))
.
Okay, noticed the edit. But filter
is the right way. Can you share an anonymous function where it is too complex?
It worked the way you proposed! Thanks very much, I was just making it more complex than it actually was and got stuck
NP. For deeply nested logic, it is sometimes helpful to use the threading macros ->
and ->>
.
if I have a set of numbers, what is the idiomatic way to make a hashmap out of them where the key is just the number and the value is a number converted to string and a fixed string concatenated to it?
typed on cellphone ... (into {} (map (juxt identity #(str % "-thing"))) #{1 2 3})
what is your code?
I personally love "for".
(into {} (for [v #{1 2 3}] [v (str v "-thing")]))
I think it's much more straightforward than map
s, juxt
s, and zip
s
I’d go for zip so here too
why not reduce? I'd do everything in one pass with it:
(reduce #(assoc %1 %2 (str %2 "-thing")) {} #{1 2 3})
I’m not the OP, but I find these threads incredibly handy, seeing many people approaching a problem from different angles.
One thing I noticed from @UE35Y835W’s answer: it produced the series out of order. Is that meaningful at all?
(reduce #(assoc %1 %2 (str %2 "-thing")) {} #{1 2 3})
=> {1 "1-thing", 3 "3-thing", 2 "2-thing"}
(The original hashmap is 1, 2, 3; it comes out as 1, 3, 2, which seemed a little weird to me as a beginner.)@UH0FTE610 hashmap does not have a reliable order. It might have one depending on internal implementation, but you should not rely on it. If you want to iterate hashmap in an ordered way, you should sort keys first, and then get values by those keys. If you'd like the hash-map to retain insertion order, you could use a specialized collection for that (you can find some here https://github.com/clj-commons/ordered)
@UH0FTE610 Practically speaking, if you eval #{1 2 3}
, it will yield #{1 3 2}
, which means that the reduce
function is consuming 3 first. Having said that there's another point to make.
The map produced by the reduce
function happens to respect the order of insertion until 8 key value pairs. Any number above that will make the key value order completely random. This magic number 8 is not something you should rely on because it might well change in the future. As I said, it just happens to work like that based on the underlining implementation details. 🙂 Hope it's clearer now.
Also, if you need the map to be ordered, I believe you would be better off with a vector of maps, where you can enforce whatever order you want.
Thank you, @UE35Y835W! The reason I noticed and asked: I had been relying on position in a hash map using positions with the assoc-in
function. Perhaps that’s a little dangerous to use. Something like (assoc-in [1 :mykey] "Updated value")
. Perhaps I should set up an :id
key instead!
In your instance, 1 is not the index but the actual key value, which means that you will always assoc in the right place no matter the actual position of the key 🙂
assoc
works on indexes instead of keys only when your collection is for example a vector:
(assoc [1 2 3] 3 "add at the end")
@UH0FTE610 In the below example, it specifically looks for the key 1.
(assoc {3 :a 2 :b 4 :c 1 :f 10 :t} 1 "new-value")
I wrote a macro that seems to work, but when I was testing it with macroexpand
it wasn’t returning me anything useful. any tips?
a common gotcha is the need to quote the form
(defmacro rid3on-> [& forms]
`(this-is this#
(rid3-> (.select d3 this#)
~@forms)))
app:cljs.user=> (macroexpand '(rid3on-> .transition (.duration 500)))
;; => (rid3on-> .transition (.duration 500))
^ that’s my macro and the repl result of trying to macro expand it
ah, perhaps that’s why
I also wrote it as a .cljc
if that has any bearing
Hey guys, do you know how to show a map the way cljs.pprint/pprint does in app as a string? With correct indendation etc? Edit: I figured it out. You need to add
(with-out-str (cljs.pprint/pprint map))
hey team! has anyone taken a course on http://purelyfunctional.tv?
i want to purchase the reply driven development course but curious on people's thoughts on these courses. is it worth it?
The REPL-Driven Development course is awesome!
I recommend that course to everyone who really wants to understand how central the REPL is and wants to develop really good practices around it.
what would you consider to be the idiomatic way to get the 2nd last item from a vector?
In some cases it might be slightly more efficient to use (my-vec (- (count my-vec) 2))
, since that will not create a new vector (`pop` does, but typically sharing almost all of its memory with the vector being popped). But I expect the performance difference would only be noticeable if that was in a pretty "hot" code path.