Fork me on GitHub
#clojure
<
2018-04-04
>
qqq04:04:17

Is it possible to rewrite https://github.com/zjhmale/intellij-paredit/blob/master/src/zjhmale/paredit/SpliceAction.java#L9-L39 using just proxy? The nested class confuses me.

the2bears04:04:16

Why do you want to re-write it?

the2bears04:04:29

And what do you mean by "just proxy"? It's been awhile since I've done Java...

qqq05:04:29

@the2bears: because I have an unhealthy obsession with preferring to rewrite libraries in Clojure instead of just modifying the java impl.

the2bears05:04:28

@qqq I don't see any reason why you can't rewrite this in Clojure. You just need the two types, the Action and the Handler. I would ignore the nesting/static nature of the handler, I don't think it's anything more than a logical way to organize the static class into the outer parent's name space. It is a member of the outer class, but that doesn't matter much in this example.

ajs08:04:34

Should it be fine to share a source file between projects using symlink?

pesterhazy09:04:12

I don't see why not

ajs09:04:51

I guess you'd have to make sure the files namespace is valid for both projects

elevi14:04:08

Hello 🙂 In some situations all of my core.async threads are either dead or stuck ( I've no idea which ), I know that they are stuck because when I connect to the remote REPL on that process, this line hang and won't return:

[root@XXX current]# rlwrap telnet localhost 5555
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
user=> (clojure.core.async/<!! (clojure.core.async/go (println "hi!")))

elevi14:04:16

do you have any idea how I can debug it ?

elevi14:04:54

I don't see any exceptions in STDERR or STDOUT

schmee14:04:50

@elevi that is because <!! is a blocking operation. it will block until there is input on the channel to take, which will never happen here

elevi14:04:42

@schmee

(clojure.core.async/go (println "hi!"))
should return immediately

tbaldridge14:04:40

There's a limited number of threads available to go blocks. Those 8 threads could be blocked.

elevi15:04:47

@tbaldridge yea so I'm apparently cause them to hang or crash, how can I debug it ? what do you guys do in these situations ?

tbaldridge15:04:39

So I'd start with looking at your channel operations. You shouldn't be doing IO or calling <!! inside a go block or inside any function called by a go block

tbaldridge15:04:11

If you are, you can switch those go blocks to core.async/thread as a test, or even switch them permanently.

elevi15:04:27

cool thanks, I'll try to convert go to thread until I'll catch it

tbaldridge15:04:36

be aware of possible false positives. You can be blocking 9 threads, and then unblock one, and suddenly the app will work, even though the remaining 8 go blocks are still configured improperly.

tbaldridge15:04:58

Feel free to post any common code here, it's a bit hard to give other suggestions without seeing the code.

elevi15:04:23

Yea I use the go blocks extensively in my program so it will be a bit hard to share all of them

justinlee15:04:32

what’s the basic intuition for the overhead of an anonymous function? in my mind it should be roughly like creating a hash map for the closed-over variables, but perhaps its more expensive than that?

tbaldridge15:04:52

@lee.justin.m no it's a lot cheaper than that, it's the cost of newing up a class.

tbaldridge15:04:45

(let [x 42] (fn [] x)) -> new AnnFn(x)

justinlee15:04:02

okay great. thanks. i’m creating a ton of them but the thing they represent is way more heavyweight than that so that shouldn’t be a problem

tomaas15:04:02

Hi, I'm using yesql with postgres. How do I parse PgArray to java/clojure collection?

tomaas15:04:46

calling .toArray method of PgArray instance throws connection closed error

tanzoniteblack15:04:49

if you're using clojure.java.jdbc (which yesql uses underneath the hood), you can extend the protocol clojure.java.jdbc/IResultSetReadColumn to handle arrays

(extend-protocol clojure.java.jdbc/IResultSetReadColumn
org.postgresql.jdbc.PgArray
(result-set-read-column [pgobj _ _]
(vec (.getArray pgobj))))

tanzoniteblack15:04:31

if you want to go the other direction (i.e. use an array as a value for a ? type arg):

(extend-protocol clojure.java.jdbc/ISQLParameter
  clojure.lang.IPersistentVector
  (set-parameter [v ^java.sql.PreparedStatement stmt ^long i]
    (let [conn (.getConnection stmt)
          meta (.getParameterMetaData stmt)
          type-name (.getParameterTypeName meta i)]
      (if-let [elem-type (when (= (first type-name) \_) (apply str (rest type-name)))]
        (.setObject stmt i (.createArrayOf conn elem-type (to-array v)))
        (.setObject stmt i v)))))

tomaas15:04:05

pfff very java solution

tomaas15:04:05

is it very dirty if I do (vec (edn/read-string (str "#" (.toString arr))))?

tanzoniteblack15:04:52

for the note, I'm pretty sure that getParameterMetaData queries the DB for information about the query, so you have an extra round trip if you use a vector as a parameter, so I'd use that pretty sparingly. The reading of a vec has very little overhead

tanzoniteblack15:04:57

that is...very dirty

elevi15:04:55

@tbaldridge do you know if put! can block a go thread ?

tbaldridge15:04:14

@elevi put! never blocks at all, but you need to make sure you handle back pressure by giving it a callback that limits how quickly future items are put onto the channel.

👍 4
ajs17:04:44

Is this back pressure handling you describe for ensuring you don't have too many pending puts on a channel?

souenzzo19:04:22

can I bind a random seed on shuffle function?

noisesmith19:04:58

@souenzzo with this library you can use a seed as a dynamic binding for it https://github.com/gfredericks/four/blob/master/src/four/stateful.clj

souenzzo20:04:17

ok. i will keep with with-redefs on my tests 🙂 tnks

pbrown22:04:04

@elevi thread dumps can be helpful too. You can run jstack $PID or kill -3 $PID to get all stacktraces (to jstack's or PID's STDOUT respectively), then look for async-dispatch. E.g.:

(clojure.core.async/go (Thread/sleep 30000))

=>

"async-dispatch-7" #171 daemon prio=5 os_prio=0 tid=0x00007fedac005000 nid=0x4b7f waiting on condition [0x00007fed34cd7000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at user$eval412060$fn__412065$state_machine__23531__auto____412066$fn__412068.invoke(NO_SOURCE_FILE:151)
        at user$eval412060$fn__412065$state_machine__23531__auto____412066.invoke(NO_SOURCE_FILE:151)
        at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:973)
        at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:972)
        at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:977)
        at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:975)
        at user$eval412060$fn__412065.invoke(NO_SOURCE_FILE:151)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)