Fork me on GitHub
#clojure
<
2019-02-24
>
craftybones05:02:33

This issue with the REPL not breaking on Ctrl-C/Ctrl-D while evaluating an infinite lazy sequence is sort of getting in my way.

dpsutton05:02:11

which repl?

hiredman05:02:23

(my guess is it isn't evaluating but printing)

craftybones05:02:38

@dpsutton off my lein repl which is the default. So repl-y I guess?

dpsutton05:02:19

lein repl and i evaluated (range) and it just sat there and spun. it obeyed a control c and gave me the prompt back. (prn (range)) and it was time to kill 🙂

dpsutton05:02:48

check (set! *print-length* 100) and then try (prn (range 1e5))

craftybones05:02:58

@dpsutton thanks. That certainly helps

parens 5
craftybones05:02:20

Is there a good use case for with-redefs

craftybones05:02:08

in actual code that is, not tests.

craftybones06:02:10

(defmulti foo class)
(defmethod foo ::collection [c] :a-collection)
(defmethod foo String [s] :a-string)

craftybones06:02:40

that’s an example given on the Clojure site

craftybones06:02:07

It says that if I execute a (foo []) then I ought to get :a-collection

craftybones06:02:50

Earlier on it derived a bunch of things from :a-collection

craftybones06:02:25

Ah, ignore. I did something wrong

craftybones06:02:37

@dpsutton The repl thing works when its just a print, but here’s where it breaks (drop-while (partial <= 0) (range))

craftybones06:02:54

And I distinctly remember that working earlier

Ho0man07:02:31

Hi, everyone I was wondering If I could write a macro to turn a map into a function defintion that resolves the keys in that map into its corresponding value using case form ... but couldnt quite get it right. (This is as far as I got ....) How is it possible (or am I getting something terribly wrong ?)

andy.fingerhut07:02:22

Not sure if you were aware, but you can "call" a map value in Clojure, like a function, passing a first argument that is some value, and it will look up that value in the map, and return the corresponding value, e.g.

user=> (def my-map {:a 1 :b -2 "c" 42})
#'user/my-map
user=> (my-map "c")
42

Ho0man08:02:40

Thanks, but yeah I knew.

Ho0man08:02:43

But the question of how to turn into a case statement using macros was just teasing me

Greg Rynkowski14:02:09

Hi everyone, I’m working on gRPC server running in Clojure. This is an example of simple method creating server:

(defn build-server [config info-service]
  (let [port (:port config)
        server (-> (ServerBuilder/forPort port)
                   (.addService ^BindableService info-service)
                   (.build)
                   (.start))]
    (println "gRPC server started listening on port" port)
    server))
In the snippet below I’m trying to pass to the server a vector of handlers and add them to the server sequently.
(defn build-server [config handlers]
  (let [port (:port config)
        server (-> (ServerBuilder/forPort port)
                   (as-> builder
                         (do (doseq [h handlers]
                               (.addService builder ^BindableService h))
                             builder))
                   (.build)
                   (.start))]
    (println "gRPC server started listening on port" port)
    server))
The thing is that the piece
(as-> builder
      (do (doseq [h handlers]
            (.addService builder ^BindableService h))
          builder))
doesn’t look elegant. I have briefly a few months of experience with Clojure and I feel there might be some handy macro or practice I’m missing.

Alex Miller (Clojure team)14:02:31

all this looks fine to me btw, but doto can help when doing a lot of java factory stuff

Greg Rynkowski14:02:56

Thanks @alexmiller, I know doto but in this piece is not going to help very much as I can’t use it with doseq. If there were a doseq returning a result of last execution :thinking_face:

daniel.spaniel15:02:20

Howdy, I am trying to send a pdf ( as ByteArrayOutputStream ) back to front end in the body of the http response. In our middle wear stack >> Transit << is barfing on that ( NullPointer ) so I am wondering if there is something I am missing. Do i have to make custom handler for transit or something?

daniel.spaniel15:02:52

my response looks like this {:status 200 :body pdf-output-stream :headers {"Content-Type" content-type}}

daniel.spaniel15:02:06

where pdf-output-stream is the byte array output stream

hmaurer16:02:03

What would be an idiomatic way to return the keys of a map for which the values match some predicate?

hmaurer16:02:41

e.g. (map first (filter #(predicate? %2) my-map)); is there a more idiomatic way?

dpsutton16:02:57

return the keys or key/value pairs?

paulocuneo16:02:05

(for [[k v] my-map :when (p? v)] k) ??

hmaurer16:02:44

ah that’s nice; thanks!

dpsutton16:02:28

(filter predicate? (keys my-map))?

hmaurer16:02:57

the predicate is on the values

dpsutton16:02:17

"for which the values". gotcha

paulocuneo16:02:08

Hi! random question 😛 why metadata impact on equality for functions?

(let [f (fn [])
        m {}]
                  (println "fn withMeta == fn"  (= (with-meta f {1 1}) f))
                  (println "m  withMeta ==  m" (= (with-meta m {1 1}) m))) 

fn withMeta == fn  false
m  withMeta ==  m true

Alex Miller (Clojure team)17:02:42

Functions have identity equality semantics. Generally you shouldn’t be comparing them for equality in the first place.

paulocuneo17:02:52

ok 😔, thanks!!

borkdude19:02:01

Function equivalence is reducible to the halting problem which cannot be solved: https://stackoverflow.com/a/1132167/6264

Lennart Buit20:02:00

You gotta love those proofs tho, suppose we have x, if we define x’ and y, we would have to solve the halting problem. That’s not possible

andy.fingerhut19:02:06

Where "cannot be solved" is the general case, for an arbitrary pair of functions. There are special cases that are decidable, but Clojure's = makes no attempt to help you find those. But I agree that point is getting fairly far from the original question 🙂

hiredman20:02:28

functions have reference equality, but implement the value metadata interface, and implement it by wrapping

dominicm21:02:18

How can I analyze a directory of files using tools.analyzer?

Greg Rynkowski22:02:01

Answering my previous question (https://clojurians.slack.com/archives/C03S1KBA2/p1551018489292000) I found a more elegant approach of expressing the same:

(defn build-server [config handlers]
  (let [port (:port config)
        server (-> (ServerBuilder/forPort port)
                   (as-> builder (reduce #(.addService %1 %2) builder handlers))
                   (.build)
                   (.start))]
    (println "gRPC server started listening on port" port)
    server))

😁 5