Fork me on GitHub
#clojure
<
2019-07-01
>
csd00:07:07

when should i use sequence instead of seq?

csd00:07:11

sounds like the answer is if working with transducers or if you want the property of nil returning ()

Alex Miller (Clojure team)02:07:35

I donโ€™t think Iโ€™ve ever used it in 10 yrs of Clojure

pinkfrog05:07:50

is there any good actor library in clojure?

dacopare06:07:20

@i There's Akka / Okku and Quasar / Pulsar, I haven't used the latter so I can't tell you if one is better than the other.

pinkfrog07:07:29

@dacopare actually i doubt the usefulness of a dedicated actor library.

pinkfrog07:07:00

i feel more like, a library will put too much constraints. actor, however, being a model, is a good pattern to follow.

dacopare07:07:17

Isn't that the point of these libraries, that they let you follow an actor model? Personally, I prefer to stick to core.async-style communicating sequential processes (CSP).

mpenet07:07:26

actors have their own set of constraints and they are not minimal either

mpenet07:07:48

especially on the jvm (no per actor gc/heap like on beam)

mpenet07:07:29

Maybe you can use akka from clj, I bet it's quite hairy but maybe interop is better nowadays

theeternalpulse08:07:14

I sometimes see clojure code online that does this (,,,) at the end of expressions. What is the purpose of this?

theeternalpulse08:07:33

I know they are essentially blanks, but why 3, why not just put nothing, or nil?

jaihindhreddy08:07:28

Used in examples as an ellipsis, a visual cue to indicate more forms may follow here

๐Ÿ‘ 4
sogaiu08:07:08

cf. http://blog.fogus.me/2013/09/04/a-ha-ha-ha-aah/ -- mentioned in the book "clojure applied" and called the "Fogus comma", apparently

theeternalpulse09:07:36

I'm actually planning on finishing that book this week. Get a week off work so planning some book time

theeternalpulse09:07:50

I found it interesting sisnce I only recently found it that it references schema, but then saw it hasn't had an edition update yet

mirza1b3911:07:38

for some reason cider repl not showing gui from swing i initialize it just returns object.. but normal repl outside works fine ,any1 had this problem?

carkh12:07:50

@mirza are you using SwingUtilities/invokeLater to ensure you're on the swing thread when doing your swing calls ?

carkh12:07:35

it has been years since i've done swing work, but i seem to remember that was a possible problem

mirza1b3912:07:32

@carkh nah havent used invokeLater

mirza1b3912:07:59

@carkh for some reason on other repl not cider it works fine

carkh12:07:22

i think a standard repl is on the main thread while nrepl isn't

mirza1b3912:07:37

thats what i thought

carkh12:07:19

it's good practice to always use invokeLater at the entry point of your swing calls anyways

mirza1b3912:07:29

yea will check

carkh12:07:25

also those pesky swing windows love to hide behind emacs

mirza1b3912:07:15

nah just checked emacs not problem works fine with eshell and lein repl command

mirza1b3913:07:33

@carkh spiral works fine , so problem is somewhere in cider

carkh13:07:10

spiral uses unrepl rather than nrepl, don't know how this one works at all

carkh13:07:20

That works for me in cider

mirza1b3907:07:17

it worked when i switched from jvm8 to 9 xd

carkh13:07:30

@mirza except that bug in the close function =)

๐Ÿ˜‚ 4
mirza1b3913:07:29

and it pops up gui ?

mirza1b3913:07:37

seems that my cider is problem then

carkh13:07:55

a small window which is only the title, behind emacs

mirza1b3913:07:08

yea cool,doesnt work for me

mirza1b3913:07:10

will reinstall

carkh13:07:18

i doubt this would help

carkh13:07:43

im'm on windows though, so this might be different

mirza1b3913:07:26

will analyze it later thanks anyway ๐Ÿ˜„

carkh13:07:31

good luck

chrisblom19:07:52

what is a good way to read back in errors printed with the #error tag?

chrisblom19:07:32

e.g i want to define a function read-error such that:

(let [ex  (ex-info "top" {} (Exception. "root"))]
  (= ex (read-error (pr-str ex))))

Alex Miller (Clojure team)19:07:01

ex here is an ExceptionInfo object wrapping an Exception Object, so you are asking for a function that reads a printed exception string and makes an Exception object? what problem are you actually trying to solve?

chrisblom20:07:08

I have a rest api that show the exception in the response body (printed as #error ...) when an exception is thrown when it handles the request

chrisblom20:07:27

i'd like to reconstruct the exceptions including causes, data etc, so i can rethrow it in the client, which lets me use cider's tooling to inspect the error

andy.fingerhut20:07:08

In general, a data conveying exception can contain references to mutable objects that are rife with issues if you attempt to serialize them between machines. Are you OK with such limitations?

chrisblom20:07:48

yeah any limitations are fine, this is just for a quick and dirty debugging session

andy.fingerhut20:07:57

e.g. objects representing open files/network-connections, etc.

ghadi20:07:03

catch the error and then call Throwable->map on it

ghadi20:07:19

the fact that it is being printed is not relevant

ghadi20:07:45

but when it is printed, it will be the representation of Throwable->map

chrisblom20:07:42

Ok, this avoids requiring a reader for 'tag which is nice, but is there a good way to convert this back to a throwable?

ghadi20:07:33

you already have an exception when you catch it

chrisblom20:07:43

yes, but that is only on the server side, i'd like to transfer it to the client so i can rethrow it there

chrisblom20:07:58

my client and server have the same code base, so if i could do something like

(let [response (call-server)] 
  (when (= 500 (:status response))
    (throw (parse-error (:body response)))))
in the client, then i can use cider to inspect the stack trace and jump to the place that caused the error

Alex Miller (Clojure team)20:07:32

while it's not impossible, I suspect making that work would be fairly tedious. in particular constructing the StackTraceElements

ghadi21:07:05

error data is better than stack traces

ghadi21:07:18

i don't know why you'd want to re-read and throw

ghadi21:07:26

something will have to re-catch

Alex Miller (Clojure team)21:07:30

if you're going between jvms, you could just use Java serialization (but beware of having all the right classes in both jvms)

chrisblom21:07:10

ah yes, thanks, java serialization works

Alex Miller (Clojure team)21:07:46

I've been down that road and it was full of all kinds of exciting pain

lukasz21:07:01

@chrisblom while not a Clojure specific solution, I wonder if it would be worth checking out Google Cloud's Debugger https://cloud.google.com/debugger/ - it allows you to inspect running code when an exception happens without performance impact. I haven't used it but sounds like might fit your requirements .

dpsutton21:07:03

@chrisblom is it possible to just connect CIDER to your server?

dpsutton21:07:24

don't know if this is a local dev server or 50 kubernetes managed servers though ๐Ÿ™‚

chrisblom21:07:52

oh no, the server is actually running in the same jvm process. I was just curious if it was possible ๐Ÿ˜

chrisblom21:07:38

Sketch of rethrowing exceptions after tranfering them:

(import '[org.apache.commons.codec.binary Base64])

(defn- decode-str [s]
  (Base64/decodeBase64 (.getBytes s)))

(defn- encode-str [bytes]
  (String. (Base64/encodeBase64 bytes)))


(let [caught-exception (->> (Exception. "root" )
                            (Exception. "b")
                            (Exception. "a")
                            (ex-info "top" {}))
      ex-response {:status 500
                   :body (-> (with-open [fos (java.io.ByteArrayOutputStream.)
                                         oos (java.io.ObjectOutputStream. fos)]
                               (.writeObject oos caught-exception)
                               (.toByteArray fos))
                             encode-str)}]
  (throw
   (with-open [fos (java.io.ByteArrayInputStream. (decode-str (:body ex-response)))
               oos (java.io.ObjectInputStream. fos)]
     (.readObject oos))))

gordon22:07:57

๐Ÿ‘‹ Can anyone help me understand the behavior of auto-gensym when used in a function called from a macro? Details in snippet:

zz848111123:07:59

what you want to do?

zz848111123:07:28

1) you should expect `s# to be the same. It's one var

zz848111123:07:12

2) your macros work as a functions and they should be a function

hiredman23:07:59

the auto gensyming happens at read time

facepalm 4
hiredman23:07:08

the form is only read once

hiredman23:07:34

user=> (read-string "(defn whatever [] `s#)")
(defn whatever [] (quote s__3__auto__))
user=> (eval (read-string "(defn whatever [] `s#)"))
#'user/whatever
user=> (whatever)
s__6__auto__
user=> (whatever)
s__6__auto__
user=>

jeff.terrell23:07:00

I think it won't cause a problem in practice, though, for the same reason that using a name in a let binding of a function body won't conflict across function calls.

gordon23:07:54

@hiredman thanks, somehow I've gone on for quite a while without realizing that happened at read time