Fork me on GitHub
#beginners
<
2018-03-07
>
Steve Upstill01:03:19

I'm embarrassed to be asking this, but it's one of those questions that should be obvious, but... So: I'm in IntelliJ Idea with Cursive, and I want to get keyboard input when I'm running a project. Is there a window for typing into a running project? Otherwise, how does one get java.io.BufferedReader. to attend to the keyboard?

mfikes01:03:30

@steve171 Normally you'd just call (read-line), but with the REPL in Cursive I believe you need to set up one choosing “Use clojure.main in normal JVM process” to get it to work.

tbaldridge01:03:34

Yeah it’s a side effect of nRepl not being a true repl

mfikes01:03:49

Ahh, I forgot, in Cursive, (read-line) will work with nRepl; it just pops up some UI for you to type into. The recommendation I gave above regarding the REPL configuration simply lets you type into the REPL box in the lower right corner of the IDE.

Steve Upstill01:03:45

@mfikes @tbaldridge Thank you! Again, the obvious solution is the correct one. Duh.

nakiya02:03:18

What’s the best channel to ask about compojure/compojure-api?

seancorfield03:03:25

@duminda Beginner questions are best asked here -- there's no channel for Compojure but there is a channel for #ring ...

Appo05:03:11

quick question on java interop why does (Math/round 2.5) work but (map #(Math/round %) [1.5 2]) does not and return a "no matching method found" error?

noisesmith05:03:42

round is not defined for Long

Appo05:03:43

oh okay, thanks

noisesmith05:03:53

you could make a multimethod if you need to accept both Long and Double args

noisesmith05:03:30

or even just use #(Math/round (double %))

nakiya08:03:39

Looks like this is illegal: (map #(update % :received_at #(.toString %)) records) I guess it’s because nested %? So, just use fn?

leonoel08:03:05

correct. you can also replace #(.toString %) by str

dl13:03:29

hey guys

dl13:03:43

is there a problem when learning clojurescript instead of clojure first?

dl13:03:51

can we use clojure script with datomic?

dl13:03:54

via node.js

beetleman13:03:44

@dl I started from clojurescript but on frontend where clojurescript realy shine. I have one side project using clojurescript on node only because i need some libs from npm and its not so nice. You dont have clojurescript libs for testing (request-mock) and db access so need to use js interop really heavy.

dl13:03:59

ok so its recommended to use clojure for the backend?

beetleman13:03:55

its depends:D but clojure with jvm ecosystem can save your time

dl13:03:43

ok thx man

dl13:03:11

I will use cljs + npm for frontend and backend to get my first experiences then

dl13:03:22

and move over to clj+datomic for serious projects

beetleman13:03:58

if you know js picking clojurescript is nice way to speedup learning

Serge13:03:58

How to build cljs project to AMD/CommonJS module?

justinlee15:03:31

@dl the biggest reason to choose clojure when you can is that the tooling (ide integration, repl connection, libraries, no need for closure compiler) is quite a bit smoother. if i were doing something on the backend with clojure i’d go with clojure instead of cljs/node for that reason unless i really needed something from the js ecosystem (or maybe if i was doing something that needed to start up quickly). just somethign to think about

unlisted19:03:28

What does <!! mean?

seancorfield19:03:15

It's just a regular function, in the core.async library: http://clojure.github.io/core.async/#clojure.core.async/&lt;!!

seancorfield19:03:52

In Clojure, symbols (names of functions etc) can include a lot of characters that would be operators and/or punctuation in other languages.

rende1120:03:58

Hello all! I have simple form :

[:div
  (form-to ["POST" "/items"]
    (label :text "Text:")
    (text-field :input)
    [:p errors]
    [:button {:type "submit"} "Send"])]
and compojure route:
(POST "/items" [input]
    (if-not (empty? input)
      (do 
        (items-db/record input)
        (redirect "/"))
      (items-view/create-item "empty input")))
How test this route with ring.mock.request (or another way) ? I don't know how send not-json body? My try:
(deftest items-post-test
  (let [body {:input ""}
        { status :status headers :headers} (app-routes (-> 
                                                          (mock/request :post "/items" {:input "test"})))]                      
(is (= 302 status))))
I also find this example - https://github.com/weavejester/ring-mock/blob/master/test/ring/mock/test/request.clj But I can't understand, where route-path (I mean "/test") here?
(testing "string body"
    (let [resp (body {} "Hello World")]
      (is (instance? InputStream (:body resp)))
      (is (= (slurp (:body resp)) "Hello World"))
      (is (= (:content-length resp) 11))))

Will23:03:49

I have a list of maps (which I am receiving from a ui) I want to save to the database which contains some new rows and some already existing rows. The way to differentiate the two, is that any object with an ID is an existing object that needs updated, any without an ID are new rows. I can 1. return them as two separate lists from the front end, 2. loop over the maps inserting / updating the rows one by one depending on if it’s new or not, or 3. split them into 2 separate lists allowing me to do bulk inserts and updates. What would be the most idiomatic approach to take in clojure?

Will23:03:35

Also if I was to split the list into 2 separate lists based on a property, how would I do that?

mfikes23:03:44

@josmith2016 split-with might work for you

mfikes23:03:07

Oh, sorry you have intermixed items…

mfikes23:03:41

Maybe group-by where f is the propery

mfikes23:03:04

As in (vals (group-by even? (range 11)))

Will23:03:01

Thanks I’ll try that

Will23:03:57

Could the predicate be where (empty? :id item-in-array) an empty string or (!empty? :id item-in-array) its not empty?