This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-28
Channels
- # adventofcode (6)
- # beginners (61)
- # boot (1)
- # chestnut (1)
- # cider (18)
- # cljs-dev (1)
- # cljsrn (3)
- # clojure (176)
- # clojure-android (8)
- # clojure-germany (12)
- # clojure-russia (4)
- # clojure-spec (7)
- # clojure-uk (5)
- # clojurescript (28)
- # css (10)
- # cursive (36)
- # datomic (7)
- # devcards (1)
- # docs (8)
- # emacs (17)
- # fulcro (29)
- # hoplon (28)
- # lein-figwheel (3)
- # leiningen (37)
- # lumo (1)
- # off-topic (54)
- # om (6)
- # re-frame (2)
- # reitit (7)
- # ring-swagger (23)
- # shadow-cljs (115)
- # sql (10)
- # uncomplicate (1)
- # unrepl (24)
is there a way of reducing an array of strings to basically just parameters? E.g. raynes/conch
is for executing shell commands and it takes the command line arguments as a variadic list of parameters…sigh….
apply
apply is similar to reduce though isnt it, in that it runs the function on each parameter?
many functions implement varargs by using reduce, that's where the similarity ends
+user=> (apply str "a" "b" ["c" "d" "e"])
"abcde"
+user=> (apply get [{:a 0} :a])
0
also ymmv but I found ProcessBuilder and Process to be more flexible and easier to use for advanced purposes compared to conch
that is, the built in java classes that conch is built on
for example I never figured out how to get real-time interactive IO with conch (send string to a process, read result, send another string in reply, etc.), it is straightforward with ProcessBuilder and Process classes
Ok, I’ll look into that if necessary. I’m mostly just messing around right now. Ok looks like apply works for the simple case, let’s see if I can get it working with programmatically adding params.
also you don't need to put args into a collection artificially - you can give your initial args to apply normally and put the rest in a collection
eg. instead of (apply str ["a" "b" "c" "d" "e"])
above I was able to use (apply str "a" "b" ["c" "d" "e"])
(let's pretend c d e came from some place interesting)
no, the collection has to come last - you'd end up with [ ] in your string
(it is "smart" enough to coerce "e" into the collection [\e] though... so that case kind of works, accidentally)
as opposed to eg. (apply + [1] 2)
which just blows up
though (apply + [1 2])
, (apply + 1 [2])
are both fine
+user=> (apply + 6 (range 9))
42
- more typical usage of applyi have (("9" "2" "5") ("1" "2" "3")) and i want [{:first "9" :second "2" :third "5"} {:first "1" :second "2" :third "3"}]
Hi… about (put! chan ....
and (go-loop [message (<! chan)] ….
is this gonna process 1 message at time? isnt async lib threads?
all operations in go loops are done in a thread pool, but there’s no automatic parallelism - if you want two workers, start two go loops
or, in your case, maybe you want to start 100 go loops
also, don’t do blocking operations inside go blocks - especially with that kind of count you can easily starve and lock up the whole thing
core.async provides a thread
macro that returns a channel
depends if you need async coordination, or just parallelism
for parallelism thread pools suffice - you can check out a nice lib called claypoole if you want a more clojure-like API
Hi, I'm trying to connect to a pg database and insert a row
user=> (require '[clojure.java.jdbc :as sql])
nil
user=> dbspec
{:dbtype "postgresql", :dbname "recipes", :host "127.0.0.1", :user "api", :password "api"}
user=> (sql/insert! dbspec :recipes {:name "oatmeal" :url ""}) (sql/insert! "" :recipes {:name "oatmeal" :url ""})
PSQLException This ResultSet is closed. org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkClosed (AbstractJdbc2ResultSet.java:2852)
from what i read, it has something to do with the connection being close, i was following along with https://devcenter.heroku.com/articles/clojure-web-application ... last updated 2017
yes ..
doh... i'm using [postgresql "9.3-1102.jdbc41"]
yep that works
thanks i thought i was going nuts 🙂
@jgh .. I see the tutorial i was looking at used the right library, i just always go to clojars to grab latest 😊
Where is the tutorial that uses the wrong PostgreSQL artifact?
I looked at that Heroku one and it has [org.postgresql/postgresql "9.4-1201-jdbc41"]
-- which is the correct group ID (not the one on Clojars!).
Since this has bitten two people recently, it seems like it's worth trying to get the tutorials updated (that are misleading folks).
well the heroku tutorial uses the wrong version, i see an old stackoverflow question that references it (and that I have clicked on, so perhaps that’s where I got it from) .. I’ve submitted an edit to fix it. There’s also a tutorial from 2016: http://enyert.github.io/rest-api-clojure-tutorial/
but i suspect it’s more like read tutorial -> want updated deps -> go to clojars instead of maven central
The Heroku tutorial uses an older driver, true, but it is at least the official one.