This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-24
Channels
- # announcements (2)
- # beginners (22)
- # cider (10)
- # clojure (47)
- # clojure-italy (2)
- # clojure-spec (2)
- # clojure-uk (1)
- # clojurebridge (5)
- # clojurescript (19)
- # cursive (1)
- # data-science (7)
- # datomic (2)
- # duct (18)
- # emacs (6)
- # figwheel-main (2)
- # java (2)
- # luminus (1)
- # nrepl (20)
- # off-topic (69)
- # om (3)
- # pathom (45)
- # quil (2)
- # re-frame (16)
- # reagent (1)
- # reitit (6)
- # ring (2)
- # shadow-cljs (33)
- # tools-deps (9)
- # vim (6)
- # yada (1)
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.
@dpsutton off my lein repl
which is the default. So repl-y I guess?
@hiredman - possible.
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 🙂
Is there a good use case for with-redefs
in actual code that is, not tests.
(defmulti foo class)
(defmethod foo ::collection [c] :a-collection)
(defmethod foo String [s] :a-string)
that’s an example given on the Clojure site
It says that if I execute a (foo [])
then I ought to get :a-collection
Earlier on it derived a bunch of things from :a-collection
Ah, ignore. I did something wrong
@dpsutton The repl thing works when its just a print, but here’s where it breaks (drop-while (partial <= 0) (range))
And I distinctly remember that working earlier
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 ?)
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
But the question of how to turn into a case statement using macros was just teasing me
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.check out doto
all this looks fine to me btw, but doto can help when doing a lot of java factory stuff
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:
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?
my response looks like this {:status 200 :body pdf-output-stream :headers {"Content-Type" content-type}}
where pdf-output-stream is the byte array output stream
What would be an idiomatic way to return the keys of a map for which the values match some predicate?
(for [[k v] my-map :when (p? v)] k) ??
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
Functions have identity equality semantics. Generally you shouldn’t be comparing them for equality in the first place.
ok 😔, thanks!!
Function equivalence is reducible to the halting problem which cannot be solved: https://stackoverflow.com/a/1132167/6264
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
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 🙂
functions have reference equality, but implement the value metadata interface, and implement it by wrapping
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))