workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | got it | 2017-12-29T12:20:59.000047 | Venessa |
clojurians | clojure | if you think about it, that's the only behaviour that makes sence as you could do `(when-let [{:keys [a b]} c] ..)` | 2017-12-29T12:21:29.000193 | Kareen |
clojurians | clojure | and in this case it would make no sense to test on `a` or `b` | 2017-12-29T12:21:44.000090 | Kareen |
clojurians | clojure | just because you are looking for a single nil? | 2017-12-29T12:22:14.000017 | Venessa |
clojurians | clojure | because when-let/if-let don't have semantics for multiple bindings | 2017-12-29T12:22:32.000171 | Kareen |
clojurians | clojure | i.e. you can't `(when-let [a b c d])` | 2017-12-29T12:22:41.000006 | Kareen |
clojurians | clojure | right — you would have to supply some predicate | 2017-12-29T12:22:46.000152 | Venessa |
clojurians | clojure | cool thanks! | 2017-12-29T12:22:56.000148 | Venessa |
clojurians | clojure | <@Venessa>
`(macroexpand-1 '(when-let [{:keys [a]} (assoc foo :a nil)] (println a)))`
=>
```
(clojure.core/let [temp__5457__auto__ (assoc foo :a nil)]
(clojure.core/when temp__5457__auto__ (clojure.core/let [{:keys [a]} temp__5457__auto__] (println a))))
```
`temp__5457__auto__` will be a map `{:a nil}`, that is truly, | 2017-12-29T12:32:21.000303 | Jutta |
clojurians | clojure | got it | 2017-12-29T12:40:13.000285 | Venessa |
clojurians | clojure | how do you `require` in an eval? ie: `clj -e "(require '[clojure.pprint :as pprint]) (pprint '(+ 1 1))"` | 2017-12-29T14:52:08.000012 | Bernice |
clojurians | clojure | I'm getting this:
```
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: pprint in this context
``` | 2017-12-29T14:56:00.000144 | Bernice |
clojurians | clojure | well you would need `"(require '[clojure.pprint :refer [pprint]]) (pprint '(+ 1 1))"` | 2017-12-29T14:56:46.000154 | Margaret |
clojurians | clojure | ```$ clj -e "(require '[clojure.pprint :refer [pprint]]) (pprint '(+ 1 1))"
(+ 1 1)``` | 2017-12-29T14:57:13.000165 | Margaret |
clojurians | clojure | ah, that works! | 2017-12-29T14:57:25.000091 | Bernice |
clojurians | clojure | now, how could I get it to work if I put it in a single file? | 2017-12-29T14:57:56.000018 | Bernice |
clojurians | clojure | that's where I get the RuntimeException: clojure ... | 2017-12-29T14:58:05.000156 | Bernice |
clojurians | clojure | the way I usually do it is `(require '[clojure.pprint :as pprint :refer [pprint]))` | 2017-12-29T14:58:06.000214 | Margaret |
clojurians | clojure | if you put what in a single file? and what’s the full RuntimeException? | 2017-12-29T14:58:44.000178 | Margaret |
clojurians | clojure | everything that works in a repl will work in a file - the rules are the same (though there are a couple of things that work in a file that are no-ops in a repl but they aren’t relevant here) | 2017-12-29T14:59:21.000152 | Margaret |
clojurians | clojure | ah, ok -- it's working now | 2017-12-29T15:00:34.000132 | Bernice |
clojurians | clojure | thanks! | 2017-12-29T15:00:35.000351 | Bernice |
clojurians | clojure | why do you use `as` and `refer`? | 2017-12-29T15:00:49.000253 | Bernice |
clojurians | clojure | :as means that I can use eg. `pprint/print-table` instead of `clojure.pprint/print-table` and :refer means that I can use `pprint` instead of `pprint/pprint` | 2017-12-29T15:01:27.000074 | Margaret |
clojurians | clojure | the doc for :as is under `(doc alias)`, the doc for :refer is under `(doc refer)` | 2017-12-29T15:01:51.000330 | Margaret |
clojurians | clojure | oic | 2017-12-29T15:01:52.000079 | Bernice |
clojurians | clojure | (that’s clojure.repl/doc but a repl will have clojure.repl in scope normally on startup) | 2017-12-29T15:02:07.000265 | Margaret |
clojurians | clojure | ok | 2017-12-29T15:08:18.000258 | Bernice |
clojurians | clojure | hrmm ... I was hoping `pprint` would render to stdout without `\n` | 2017-12-29T15:08:38.000165 | Bernice |
clojurians | clojure | you could pass a StringWriter or use `with-out-str`, then trim the resulting string (hacky, but simpler than any other option I can think of here) | 2017-12-29T15:11:58.000113 | Margaret |
clojurians | clojure | <@Bernice> ```(ins)user=> (let [sw (java.io.StringWriter.)] (pprint {:a 0 :b 1} sw) (str sw))
"{:a 0, :b 1}\n"
(ins)user=> (let [sw (java.io.StringWriter.)] (pprint {:a 0 :b 1} sw) (clojure.string/trim (str sw)))
"{:a 0, :b 1}"
(ins)user=> (let [sw (java.io.StringWriter.)] (pprint {:a 0 :b 1} sw) (print (clojure.string/trim (str sw))))
{:a 0, :b 1}nil``` | 2017-12-29T15:13:13.000014 | Margaret |
clojurians | clojure | hrmm ... those aren't spitting out anything for me | 2017-12-29T15:16:30.000036 | Bernice |
clojurians | clojure | right, without a newline you need to use `(flush)` to force output | 2017-12-29T15:17:50.000156 | Margaret |
clojurians | clojure | the vm will-auto-flush on newline but without that you need to flush by hand | 2017-12-29T15:18:04.000207 | Margaret |
clojurians | clojure | (and of course just making a string won’t make anything print to the console when running a program - in the ones not using print) | 2017-12-29T15:18:57.000144 | Margaret |
clojurians | clojure | `something.clj`
```
(require '[clojure.pprint :as pprint :refer [pprint]])
(let [sw (java.io.StringWriter.)]
(pprint '(+ 1 1) sw)
(flush))
```
`clj something.clj` returns nothing | 2017-12-29T15:19:59.000078 | Bernice |
clojurians | clojure | right, pprint with sw as an arg returns a string | 2017-12-29T15:20:41.000117 | Margaret |
clojurians | clojure | you need to use print | 2017-12-29T15:20:44.000049 | Margaret |
clojurians | clojure | well, it puts something in sw, you need to call str to get a string out of sw | 2017-12-29T15:21:01.000003 | Margaret |
clojurians | clojure | then you need to print that string | 2017-12-29T15:21:07.000042 | Margaret |
clojurians | clojure | the extra arg to pprint is a writer, it overrides `*out*` as the place to put the output - and you need to use clojure.string/trim on the resulting string to remove the newline (as in my example above) | 2017-12-29T15:21:55.000209 | Margaret |
clojurians | clojure | hrmm ... and it looks like I'm back to where I was without the `sw` | 2017-12-29T15:24:02.000053 | Bernice |
clojurians | clojure | you need sw in order to trim the string - but I showed everything you need in my example | 2017-12-29T15:24:20.000184 | Margaret |
clojurians | clojure | ```
clj something.clj
"(ns guestbook.db\n (:require\n
...
``` | 2017-12-29T15:24:25.000101 | Bernice |
clojurians | clojure | here's my `something.clj` now:
```
(require '[clojure.pprint :as pprint :refer [pprint]])
(let [sw (java.io.StringWriter.)]
(pprint (slurp "./db.cljs") sw)
(print (clojure.string/trim (str sw)))
(flush))
``` | 2017-12-29T15:25:10.000170 | Bernice |
clojurians | clojure | that should do what you want | 2017-12-29T15:25:32.000039 | Margaret |
clojurians | clojure | (you might need to require clojure.string) | 2017-12-29T15:25:48.000085 | Margaret |
clojurians | clojure | but it's resulting in the same output as
```
(require '[clojure.pprint :as pprint :refer [pprint]])
(pprint (slurp "./db.cljs")
``` | 2017-12-29T15:26:09.000073 | Bernice |
clojurians | clojure | well slurp returns a string - pprint of a string just adds “” and otherwise acts like println | 2017-12-29T15:26:41.000031 | Margaret |
clojurians | clojure | err… it also prints \n instead of real newlines inside the string etc. | 2017-12-29T15:27:04.000080 | Margaret |
clojurians | clojure | so maybe it's slurp that's messin' me up :confused: | 2017-12-29T15:28:13.000089 | Bernice |
clojurians | clojure | :laughing: all I want is to run <https://github.com/weavejester/cljfmt> at the CLI without a lein project | 2017-12-29T15:28:34.000186 | Bernice |
clojurians | clojure | haha yeah this sounds like a hell of an x/y then | 2017-12-29T15:28:57.000043 | Margaret |
clojurians | clojure | it’s too bad cljfmt and lein-cljfmt aren’t separate projects | 2017-12-29T15:29:36.000087 | Margaret |
clojurians | clojure | oh wait they are | 2017-12-29T15:29:44.000217 | Margaret |
clojurians | clojure | (just one github) | 2017-12-29T15:29:48.000052 | Margaret |
clojurians | clojure | oh -- can I use like `deps.edn` to grab it and use it via the CLI? | 2017-12-29T15:30:13.000095 | Bernice |
clojurians | clojure | yeah - you can use cljfmt without the lein stuff - looks like a straightforward ns to use <https://github.com/weavejester/cljfmt/blob/master/cljfmt/src/cljfmt/core.cljc> | 2017-12-29T15:30:38.000268 | Margaret |
clojurians | clojure | <https://clojars.org/cljfmt> - this is the clojars dep | 2017-12-29T15:30:58.000170 | Margaret |
clojurians | clojure | :laughing: `slurp` messes me up there too | 2017-12-29T15:35:23.000264 | Bernice |
clojurians | clojure | same output as `pprint` | 2017-12-29T15:35:31.000081 | Bernice |
clojurians | clojure | cljfmt has functions for forms and for strings though | 2017-12-29T15:35:45.000067 | Margaret |
clojurians | clojure | and you can use `clojure.edn/read-string` to get forms out of a string (or attempt it at least) | 2017-12-29T15:35:59.000083 | Margaret |
clojurians | clojure | ```
(def create-handles (fn [] (let [cudnn-h (cudnn-handle)
_ (cudnn-create cudnn-h)
src-tensor-d (cudnn-tensor-d)
dst-tensor-d (cudnn-tensor-d)
bias-tensor-d (cudnn-tensor-d)
filter-d (cudnn-filter-d)
conv-d (cudnn-conv-d)
pooling-d (cudnn-pooling-d)
norm-d (cudnn-lrn-d)
cublas-h (cublas-handle)
_ (cublas-create cublas-h)]
{::cudnn-h cudnn-h
::src-tensor-d src-tensor-d
::dst-tensor-d dst-tensor-d
::blas-tensor-d blas-tensor-d
::filter-d filter-d
::conv-d conv-d
::pooling-d pooling-d
::norm-d norm-d
::cublas-h cublas-h})))
```
is there a way to shorten this code? There seems to be too much repetition. | 2017-12-29T15:38:13.000193 | Berry |
clojurians | clojure | that let block is pointless - just put the forms in the hash-map | 2017-12-29T15:38:41.000218 | Margaret |
clojurians | clojure | it’s just noise | 2017-12-29T15:38:44.000066 | Margaret |
clojurians | clojure | the order slightly amtters | 2017-12-29T15:38:54.000073 | Berry |
clojurians | clojure | (except for the things to reuse one of the the bindings | 2017-12-29T15:39:00.000034 | Margaret |
clojurians | clojure | ) | 2017-12-29T15:39:01.000155 | Margaret |
clojurians | clojure | then call ~into~ assoc | 2017-12-29T15:39:05.000079 | Margaret |
clojurians | clojure | I need to create the cudnn handle before calling the other functions, as these are java bindings | 2017-12-29T15:39:09.000222 | Berry |
clojurians | clojure | ```(defn create-handles
[]
(let [cudnn-h (cudnn-handle)]
(cudnn-create cudnn-h)
(assoc {:cudnn-h cudnn-h}
::src-tensor-d (cudnn-tensor-d)
...)))``` | 2017-12-29T15:41:03.000274 | Margaret |
clojurians | clojure | biting the bullet -- /me installing lein | 2017-12-29T15:47:49.000153 | Bernice |
clojurians | clojure | ```(fn []
(into {::cudnn-h (doto (cudnn-handle) (cudnn-create))
::cublas-h (doto (cublas-handle) (cublas-create))}
{::src-tensor-d (cudnn-tensor-d)
::dst-tensor-d (cudnn-tensor-d)
::bias-tensor-d (cudnn-tensor-d)
::filter-d (cudnn-filter-d)
::conv-d (cudnn-conv-d)
::pooling-d (cudnn-pooling-d)
::norm-d (cudnn-lrn-d)}))```
I _think_ this works too | 2017-12-29T15:48:35.000007 | Berry |
clojurians | clojure | oh, if that’s the only part of the order that matters, yeah | 2017-12-29T15:49:00.000027 | Margaret |
clojurians | clojure | but the assoc is nicer imho and does the same thing | 2017-12-29T15:49:20.000144 | Margaret |
clojurians | clojure | (and also guarantees evaluation order) | 2017-12-29T15:49:30.000080 | Margaret |
clojurians | clojure | I guess it comes down to whether the extra {} are an improvement or background noise | 2017-12-29T15:50:20.000041 | Margaret |
clojurians | clojure | you know, what, I'm going to use assoc, just in case the ordering is stricter than I think it is, - in which case mine may cause a non deterministic bug | 2017-12-29T15:50:25.000083 | Berry |
clojurians | clojure | usage of assoc with many keys in one call us under-appreciated IMHO :smile: | 2017-12-29T15:50:56.000046 | Margaret |
clojurians | clojure | to make it all "uniform", I'm going with:
```
(assoc {}
::cudnn-h (doto (cudnn-handle) (cudnn-create))
::cublas-h (doto (cublas-handle) (cublas-create))
::src-tensor-d (cudnn-tensor-d)
::dst-tensor-d (cudnn-tensor-d)
::bias-tensor-d (cudnn-tensor-d)
::filter-d (cudnn-filter-d)
::conv-d (cudnn-conv-d)
::pooling-d (cudnn-pooling-d)
::norm-d (cudnn-lrn-d))
```
the only slight problem is that cider indent doesn't auto indent the assoc k v pairs for me | 2017-12-29T15:52:51.000195 | Berry |
clojurians | clojure | on behalf of Boz I welcome this pull request :smile: | 2017-12-29T18:14:52.000023 | Charity |
clojurians | clojure | meh, everytime I've aligned arguments in `let` or in maps I've always regretted it | 2017-12-29T18:58:32.000099 | Kareen |
clojurians | clojure | it just ends up messing up git history | 2017-12-29T18:59:00.000098 | Kareen |
clojurians | clojure | FWIW, git has some affordance for ignoring whitespace changes—see the `-b` and `-w` options to `git diff`, for example. (GitHub and GitLab have the same feature in diff view, although it's not always obvious how to toggle it.) That's not meant to disagree about alignment though. | 2017-12-29T19:54:58.000053 | Adelaida |
clojurians | clojure | "Note: there is no support for inline value specification, by design." <https://clojuredocs.org/clojure.spec/keys>
wondering if someone has a cool `keys` drop-in that supports them
(I agree with the `spec` principles btw... but sometimes I just know what I'm doing ;)) | 2017-12-29T20:04:20.000036 | Kristy |
clojurians | clojure | One day we'll all use fully AST aware editors and argument / binding alignment will be a UI option :stuck_out_tongue: | 2017-12-29T20:04:48.000036 | Charity |
clojurians | clojure | Not excessively hard to implement... syntax would be `:req [int? ::foo ::bar ::baz]` where `int?` means a predicate for the following keyword, `:foo`. Similar to metadata syntax (note that kws aren't IMetas)
will give it a shot someday | 2017-12-29T20:15:14.000036 | Kristy |
clojurians | clojure | has anyone used refs and STMs in production code? I’m struggling to sea use case where it is favorable to use over one big atom | 2017-12-30T00:13:25.000012 | Danielle |
clojurians | clojure | If it's possible to partition the problem you're trying to solve into several effect scopes (say several queues such that most STM is only between two of N queues), the STM tools Clojure includes can be useful and meaningfully reduce contention between multiple threads. | 2017-12-30T00:24:59.000052 | Charity |
clojurians | clojure | In general they tend to be rarely used especially in library code because that's a super application-specific property which requires global knowledge of your system and its state update behavior to leverage. | 2017-12-30T00:26:07.000066 | Charity |
clojurians | clojure | It's also easier (makes fewer fragile assumptions) to structure your application as a bunch of computation followed by a big-bang `swap!` using some comparatively cheap state merging function. | 2017-12-30T00:28:06.000097 | Charity |
clojurians | clojure | <@Danielle> FWIW, we have 75,000 lines of Clojure and only a small number of atoms and a few agents. We have no refs. I think that out in the real world, STM is rarely used -- but can be very valuable in the (very) few edge cases where it is actually appropriate. So, yeah, what <@Charity> said :slightly_smiling_face: | 2017-12-30T01:41:35.000033 | Daniell |
clojurians | clojure | actually, I can't think of a single situation where I have seem STM used; most concurrency problems seems solvable via: build new data structure, do a pointer swap at the last moment | 2017-12-30T01:44:27.000043 | Berry |
clojurians | clojure | i.e., `atom`s, yes. | 2017-12-30T01:46:23.000013 | Daniell |
clojurians | clojure | (or `agent`s) | 2017-12-30T01:46:29.000045 | Daniell |
clojurians | clojure | I wonder if the rise of core.async headed off a lot of what refs might have otherwise been used for? | 2017-12-30T01:50:41.000046 | Daniell |
clojurians | clojure | probably; though for me, it's mostly <http://curtclifton.net/papers/MoseleyMarks06a.pdf> | 2017-12-30T02:01:56.000081 | Berry |
clojurians | clojure | thanks for the thoughts folks. | 2017-12-30T02:13:49.000050 | Danielle |
clojurians | clojure | <@Danielle> one place I do see STM constructs (although not many) is clojurescript. | 2017-12-30T04:44:02.000073 | Jodie |