Fork me on GitHub
#beginners
<
2020-04-17
>
Patryk Wilson06:04:51

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

Patryk Wilson06:04:36

This is my path btw with my clj file being within src C:\Users\Cayendo\Programming\FirstClojureProject\src

andy.fingerhut07:04:39

FYI if you do not get an answer here, there is a #cursive channel, too.

hindol07:04:11

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.

Patryk Wilson07:04:31

I do have Clojure CLI installed so not sure what else I need to do

hindol08:04:05

Do you have it in your PATH?

hindol08:04:50

You might have more options in the settings pane of Cursive.

hindol08:04:21

E.g. it might be possible to provide an absolute path to Clojure CLI.

Patryk Wilson17:04:53

I only have a few options of disable and uninstall

Patryk Wilson17:04:31

There are other options as well of managing repositories and HTTP

Patryk Wilson17:04:30

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

Patryk Wilson17:04:40

I have my Clojure CLI Tools located at C:\Program Files\WindowsPowerShell\Modules\ClojureTools

hindol17:04:52

That looks like a PowerShell module. Does the command clojure and clj work outside PowerShell?

Patryk Wilson17:04:33

No it does not

hindol18:04:58

I doubt Cursive can "see" the PowerShell module.

hindol18:04:44

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?

Patryk Wilson19:04:09

Thats seems to have fixed my issues. Thanks a lot

ashnur08:04:26

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

didibus08:04:02

There's sorted-map as well, that sorts based on some comparator function. For insertion order, there's nothing in core.

AlesH08:04:14

If you create the sorted-map from a coll, you could use map-indexed and add an :order to your items

kelveden10:04:58

(It's just Clojure - not ClojureScript though.)

jakuzure09:04:13

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

jakuzure09:04:13

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

hindol09:04:02

You use filter. By the way, keywords are functions, so #(map :is_video (hot!)) works. So does (filter :is_video (hot!)).

hindol10:04:41

Okay, noticed the edit. But filter is the right way. Can you share an anonymous function where it is too complex?

jakuzure10:04:20

It worked the way you proposed! Thanks very much, I was just making it more complex than it actually was and got stuck

hindol10:04:12

NP. For deeply nested logic, it is sometimes helpful to use the threading macros -> and ->>.

ashnur10:04:56

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?

ashnur10:04:25

something like #{1 2 3} -> {1 "1-thing" 2 "2-thing" 3 "3-thing"}

ashnur10:04:54

numbers are not this nice 🙂

ashnur10:04:31

I am using a zipmap, map, str combination now

Vincent Cantin11:04:24

typed on cellphone ... (into {} (map (juxt identity #(str % "-thing"))) #{1 2 3})

ashnur11:04:06

well, that's even more complicated 🙂

Vincent Cantin11:04:12

what is your code?

ashnur11:04:08

(zipmap result (map #(str % "-thing) inputs)

Timur Latypoff11:04:26

I personally love "for". (into {} (for [v #{1 2 3}] [v (str v "-thing")])) I think it's much more straightforward than maps, juxts, and zips

Darin Douglass12:04:31

I’d go for zip so here too

Lu12:04:21

why not reduce? I'd do everything in one pass with it:

(reduce #(assoc %1 %2 (str %2 "-thing")) {} #{1 2 3})

Scott Starkey12:04:40

I’m not the OP, but I find these threads incredibly handy, seeing many people approaching a problem from different angles.

Scott Starkey12:04:11

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

Timur Latypoff12:04:12

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

Lu13:04:08

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

Lu13:04:09

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.

Scott Starkey13:04:31

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!

Lu13:04:38

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 🙂

Lu13:04:32

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

Lu13:04:37

@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")

ashnur17:04:48

Huh, does this mean that my zipmap code is also faulty?

ashnur18:04:35

yeah, it does, going to use the juxt thing

introom01:04:22

zipmap is not faulty…. the order the same for both keys and vals.

ashnur01:04:29

I didn't say zipmap faulty, I said my code using zipmap is. "zipmap code" != "zipmap"

ashnur01:04:56

basically, the read order was different sometimes

ryan echternacht17:04:45

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?

noisesmith17:04:11

a common gotcha is the need to quote the form

ryan echternacht17:04:28

(defmacro rid3on-> [& forms]
  `(this-is this#
            (rid3-> (.select d3 this#)
                    [email protected])))

app:cljs.user=> (macroexpand '(rid3on-> .transition (.duration 500)))
;; => (rid3on-> .transition (.duration 500))

ryan echternacht17:04:36

^ that’s my macro and the repl result of trying to macro expand it

dpsutton17:04:53

cljs macros are a different beast

ryan echternacht17:04:09

ah, perhaps that’s why

ryan echternacht17:04:13

I also wrote it as a .cljc if that has any bearing

Shako Farhad17:04:28

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

tjb22:04:37

hey team! has anyone taken a course on http://purelyfunctional.tv?

tjb22:04:07

i want to purchase the reply driven development course but curious on people's thoughts on these courses. is it worth it?

seancorfield22:04:24

The REPL-Driven Development course is awesome!

seancorfield22:04:07

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.

tjb22:04:23

wahoo!!!

tjb22:04:27

ill buy it this weekend then 🙂

Bill Phillips00:04:40

i’m a n00b and i’m going through it, and I’d say it’s useful

robertfw23:04:27

what would you consider to be the idiomatic way to get the 2nd last item from a vector?

dpsutton23:04:22

(peek (pop coll))

robertfw23:04:32

of course. thanks 🙂

andy.fingerhut23:04:25

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.

didibus06:04:48

I kind of find this more readable as well to some extent