Fork me on GitHub
#clojure
<
2019-08-16
>
Benny kach07:08:19

great explanation. thx a lot!

borkdude08:08:07

how do I create a transit reader from *in*?

borkdude08:08:22

maybe it makes sense to first read json values from the inputstream and then feed them into transit read-string?

vlaaad08:08:27

the problem is *in* is a Reader, and transit wants InputStream, right?

vlaaad08:08:49

there is org.apache.commons.io.input.ReaderInputStream to transform one to another

borkdude09:08:09

@vlaaad thanks, that worked

borkdude09:08:02

this is what I got right now, it's a bit iffy:

(defn transit-reader []
  (transit/reader (ReaderInputStream. *in*) :json))

(defn parse-transit [rdr]
  (try (transit/read rdr)
       (catch java.lang.RuntimeException e
         (if-let [cause (.getCause e)]
           (if (instance? java.io.EOFException cause)
             ::EOF
             (throw e))
           (throw e)))))

borkdude09:08:16

but I guess it does the job

vlaaad09:08:34

looks fine to me, although you should specify charset in ReaderInputStream constructor: https://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/input/ReaderInputStream.html 1-arg constructor is deprecated

borkdude09:08:02

hmm, how can I know the charset when reading from stdin?

skuro12:08:54

but most likely you just a) assume a default b) switch encoding with optional args / config / etc.

cjsauer14:08:52

What is generally implied by a Clojure programmer when a trailing asterisk is used in a function name, e.g. my-cool-fn*?

matthavener14:08:32

I usually assume its a implementation/helper function called by my-cool-fn

👍 4
cjsauer15:08:45

Okay. So then the details of my-cool-fn* are likely uninteresting, or distract from the clarity of my-cool-fn, and a better name really isn’t available?

cjsauer15:08:30

It seems like a common idiom to keep let blocks clear

cjsauer15:08:02

And often there just isn’t a good name, or that the function is very coupled to the sans-asterisk fn.

joelsanchez15:08:11

sometimes my-cool-fn is boilerplate and my-cool-fn* does the actual work, and this is done to make my-cool-fn* clearer (and not the opposite)

1
cjsauer15:08:32

Ah okay, that makes sense. Almost as if my-cool-fn is the “public facing” function. The gory details can be kept elsewhere for clarity.

👍 1
✔️ 1
cjsauer15:08:38

Thanks all 🙏

alexmiller15:08:04

if you have a macro that expands to a function, that function needs to be public, but is often not the public api

Benny kach17:08:27

I have upgraded our project to clojure 1.10 and there is this error:

:cause Call to clojure.core/refer-clojure did not conform to spec.
:message Syntax error macroexpanding clojure.core/refer-clojure at (clojure/core/async.clj:9:1).

Benny kach18:08:54

I see the commit that should fix it but for some reason i have old version of core.async

noisesmith18:08:18

@bennyk this is something to sort out in your dep manager (often the solution is depending a specific newer core.async before depending anything that would pull in another version)

Benny kach18:08:30

yea its leiningen, maybe someone knows how to fix it?

noisesmith18:08:40

then the fix is to ask for a newer core.async version in your :dependencies, before anaything that depends on core.async

noisesmith18:08:04

you can also look at lein deps :tree and lein deps :why org.clojure/core.async for more detailed info

Benny kach18:08:54

great! thx a lot!

chrisulloa18:08:49

Might also be worth checking your ~/.lein/profiles.clj, if you have one