workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
on can’t “break out” of reduce. one has basically to walk though the entire collection…
2017-12-26T18:03:08.000042
Marcel
clojurians
clojure
well, it's actually possible to break out of a reduce
2017-12-26T18:03:30.000050
Ambrose
clojurians
clojure
because clojure provides a special way to signal that you want to break out early
2017-12-26T18:04:01.000160
Ambrose
clojurians
clojure
but I'd avoid that until you're more comfortable with reduce and FP in general
2017-12-26T18:04:27.000090
Ambrose
clojurians
clojure
`reduced`?
2017-12-26T18:04:33.000016
Marcel
clojurians
clojure
yep
2017-12-26T18:04:35.000096
Ambrose
clojurians
clojure
loop/recur's name is a bit unlucky, since newcomers often think it's similar to an imperative loop
2017-12-26T18:08:32.000137
Ambrose
clojurians
clojure
it’s an end-tailed recursion, right?
2017-12-26T18:08:49.000089
Marcel
clojurians
clojure
yeah
2017-12-26T18:08:58.000135
Ambrose
clojurians
clojure
you can `recur` without `loop`, too
2017-12-26T18:09:08.000118
Ambrose
clojurians
clojure
in which case it'll just recurse from the beginning of the function
2017-12-26T18:09:25.000097
Ambrose
clojurians
clojure
*tail recursion
2017-12-26T18:09:27.000094
Marcel
clojurians
clojure
oh what
2017-12-26T18:09:46.000012
Marcel
clojurians
clojure
but without the tail optimization, correct? stack or heap would fill up
2017-12-26T18:10:32.000003
Marcel
clojurians
clojure
*with the optimization, you mean?
2017-12-26T18:10:55.000141
Ambrose
clojurians
clojure
oh, I see
2017-12-26T18:11:14.000037
Ambrose
clojurians
clojure
recur tells clojure to use tail optimization
2017-12-26T18:11:33.000001
Ambrose
clojurians
clojure
just calling recur would omit optimizations
2017-12-26T18:11:34.000032
Marcel
clojurians
clojure
ah
2017-12-26T18:11:36.000071
Marcel
clojurians
clojure
what does loop do then?
2017-12-26T18:11:48.000106
Marcel
clojurians
clojure
if you just called the function itself you'd fill up the stack
2017-12-26T18:11:52.000070
Ambrose
clojurians
clojure
loop just localizes it
2017-12-26T18:11:57.000009
Ambrose
clojurians
clojure
ah loop is just the jump-point for recur?
2017-12-26T18:12:00.000129
Marcel
clojurians
clojure
yep
2017-12-26T18:12:03.000077
Ambrose
clojurians
clojure
for when you don't want to go all the way back to the beginning of a function
2017-12-26T18:12:17.000038
Ambrose
clojurians
clojure
also you can recur to a function - loop is just a convenience if the loop bindings shouldn't be your function args
2017-12-26T19:38:52.000161
Margaret
clojurians
clojure
The key thing is that `recur` may only appear in a tail position -- and therefore it _is always optimized_. The compiler won't allow you to `recur` in a position that couldn't be optimized.
2017-12-26T19:59:48.000044
Daniell
clojurians
clojure
Hi, just wondering, how do you guys use spec for data validation? Using `:pre` in `defn` helps in a way to ensure that the function can't be called with unsuitable arguments. But the resulting AssertionError is not really helpful for composing error message to the user. I mean, I don't want to return "Assert failed: (spec/valid? ::email email)" as the error message to the user. Something like: "Invalid format for email" is good enough for me as of now.
2017-12-27T03:07:02.000036
Marvin
clojurians
clojure
I came across this <https://groups.google.com/forum/#!topic/clojure/H9tk04sSTWE> It gave me some clarity, but any thoughts here will still be appreciated :slightly_smiling_face:
2017-12-27T03:19:24.000160
Marvin
clojurians
clojure
thank’s for explaining :slightly_smiling_face:
2017-12-27T04:46:24.000048
Marcel
clojurians
clojure
the spec guide <https://clojure.org/guides/spec#_testing> has a snippet on how to test all spec'ed functions from an ns `(-&gt; (stest/enumerate-namespace 'user) stest/check)`. Where should I add this in a classic clojure.test file? Adding it just like that produces 0 tests. Wrapping it in a deftest produces 1 tests with 0 assertions..
2017-12-27T04:52:54.000144
Ahmed
clojurians
clojure
``` (counted? (float-array [1 2 3])) (comment false) ``` what is the constant time way to get the size of a float-array ?
2017-12-27T06:54:30.000037
Berry
clojurians
clojure
it dousn't implement clojure.lang.Counted because it's not a clojure type
2017-12-27T07:48:46.000003
Margaret
clojurians
clojure
it still supports count in constant time
2017-12-27T07:48:54.000024
Margaret
clojurians
clojure
```user=&gt; (source counted?) (defn counted? "Returns true if coll implements count in constant time" {:added "1.0" :static true} [coll] (instance? clojure.lang.Counted coll)) nil ```
2017-12-27T07:49:19.000226
Margaret
clojurians
clojure
<@Daniell> does the compiler similarly optimize non-`recur` recursion when it's in the tail position ?
2017-12-27T09:32:24.000056
Beulah
clojurians
clojure
no, this feature is intentionally missing
2017-12-27T09:35:33.000365
Margaret
clojurians
clojure
explicit is better
2017-12-27T09:37:38.000090
Beulah
clojurians
clojure
<@Margaret> actually, shouldn't `recur` be called `iterate` (I know `iterate` has been used) ? it's not recursion when it's in the tail-position
2017-12-27T09:39:45.000235
Beulah
clojurians
clojure
it's still recursion, a tail recursion is trivially translated into a goto
2017-12-27T10:12:42.000155
Margaret
clojurians
clojure
but that's an implementation detail - aside from stack usage the behavior is the same as direct recursion
2017-12-27T10:13:09.000100
Margaret
clojurians
clojure
:wave: I recently converted a clojurescript project to use mostly cljc (to possibly move towards clojure), but now i'm getting a :boat: load of errors when I boot my cljs project: `java.lang.RuntimeException: Unable to resolve symbol: defproject in this context, compiling:(project.clj:1:1)` usually starting with that :arrow_left: . Strangely enough everything still works. Sound familiar with anyone?
2017-12-27T10:34:32.000354
Huey
clojurians
clojure
Looking for a working proxy middleware for ring. Have tried tailrecursion/ring-proxy but running into errors. Any recommendations?
2017-12-27T10:37:22.000455
Inocencia
clojurians
clojure
More specifically looking for a proxy configuration that can work with figwheel: <https://github.com/bhauman/lein-figwheel/issues/634>
2017-12-27T10:42:52.000039
Inocencia
clojurians
clojure
is your source path for cljs set up so it would find project.clj?
2017-12-27T10:52:40.000014
Margaret
clojurians
clojure
I'm currently using the lein checkouts feature ... and I also have the third party lib cljc thing as a dependency...
2017-12-27T10:58:56.000074
Huey
clojurians
clojure
ie. for my shared cljc lib I have run "lein install", and am now referencing that as a dependency as well as using the lein checkouts sym link features to make use of it. Everything _appears_ to work, but I am seeing these errors on boot.
2017-12-27T10:59:45.000242
Huey
clojurians
clojure
the errors look like so: ``` Reloading Clojure file "/src/myproject/myfile.cljc" failed. clojure.lang.Compiler$CompilerException: java.lang.IllegalAccessError: MY-FUNCTION does not exist, compiling:(src/myproject/myfile.cljc:1:1) ```
2017-12-27T11:01:00.000021
Huey
clojurians
clojure
Hi all, can you tell me why `tree-seq` is flattening my tree? My code is like this: ``` (defn to-tree [root] (let [name (:name root) reg @registry] (tree-seq #(some? (:childs (get reg %))) #(:childs (get reg %)) name))) ``` `registry` is a giant atom map with `{"xxx" {:name "aaa" :childs ["yyy" "zzz"]}}`
2017-12-27T11:09:33.000111
Ross
clojurians
clojure
I know, it isn’t very functional; I’m calling `(to-tree "xxx")`
2017-12-27T11:09:39.000010
Ross
clojurians
clojure
but I get a flat sequence `("xxx" "yyy" "zzz") `
2017-12-27T11:10:43.000111
Ross
clojurians
clojure
&gt; Returns a lazy sequence of the nodes in a tree, via a depth-first walk. that seems to be what it promises? perhaps you want something in `clojure.walk`?
2017-12-27T11:32:27.000242
Willow
clojurians
clojure
I was hoping to get something like `("xxx" ("yyy" "zzz" (...))`
2017-12-27T11:37:53.000175
Ross
clojurians
clojure
I don’t have any help for you but just want to say thank you for working on this. This feature would be very helpful.
2017-12-27T11:48:44.000014
Thu
clojurians
clojure
yeah, you want clojure.walk/post-walk for that likely
2017-12-27T12:59:10.000144
Margaret
clojurians
clojure
tree-seq is useful if you have no assumptions about the shape of the data, but you know what the thing you want looks like (so you can filter and find it)
2017-12-27T12:59:39.000199
Margaret
clojurians
clojure
post-walk / pre-walk / walk are for doing a transformation in the shape of the original collection
2017-12-27T12:59:55.000243
Margaret
clojurians
clojure
When is the 2017 Clojure survey?
2017-12-27T14:16:00.000214
Johana
clojurians
clojure
<@Sonny> ^ ? Last year it was opened in early-ish December (12th) and the results came out in early February (7th).
2017-12-27T14:32:46.000131
Daniell
clojurians
clojure
Folks, what is the better/more idiomatic/shorter way to sort+print a vector of elements than ``` (doall (map #(-&gt; % format-value println) (sort-by some-fn some-vector)))```?
2017-12-27T15:21:57.000123
Maryann
clojurians
clojure
drop the 'doall' and replace 'map' with 'run!'?
2017-12-27T15:23:21.000027
Bibi
clojurians
clojure
also consider `(doseq [value (sort-by some-fn some-vector)] (println (format-value value)))`
2017-12-27T15:26:19.000289
Margaret
clojurians
clojure
also, if using map instead of run! (eg. for clojure version reasons or to take extra args like map does) use dorun instead of doall, since the value returned is not something you want or need (just a sequence of nils)
2017-12-27T15:27:12.000179
Margaret
clojurians
clojure
`(run! #(println (format-value %)) (sort-by some-fn some-vector))` looks better, thanks.
2017-12-27T15:33:24.000026
Maryann
clojurians
clojure
for fancy fp-gangsta points you can replace that function with the equivalent `(comp println format-value)`
2017-12-27T15:37:52.000319
Margaret
clojurians
clojure
``` (-&gt;&gt; some-vector (sort-by some-fn) (mapv (comp println format-value))) ```
2017-12-27T15:39:57.000257
Ambrose
clojurians
clojure
run! is much better than mapv here
2017-12-27T15:40:22.000304
Margaret
clojurians
clojure
agreed
2017-12-27T15:40:38.000050
Ambrose
clojurians
clojure
``` (defn get-data [] (<http://clojure.java.io/make-parents|clojure.java.io/make-parents> (str (mnist-config :data-dir) "foo")) (doseq [[k url] (select-keys mnist-config [:train-images :train-labels :t10k-images :t10k-labels])] (with-open [in (java.util.zip.GZIPInputStream. (<http://clojure.java.io/input-stream|clojure.java.io/input-stream> url))] (spit (str (mnist-config :data-dir) (name k)) (slurp in))))) (get-data) ``` is there a better way to write this? in particular, the (spit ... (slurp ...)) seems redundant We're downloading a bunch of *.gz files, gunziping thej,m, and writing it out to file
2017-12-27T15:47:39.000226
Berry
clojurians
clojure
`<http://clojure.java.io/copy|clojure.java.io/copy>` perhaps?
2017-12-27T15:48:07.000234
Daniell
clojurians
clojure
Oh wait, you're slurping an input stream... not sure if copy will do that...
2017-12-27T15:48:27.000118
Daniell
clojurians
clojure
you can write an inputstream directly though
2017-12-27T15:49:49.000141
Margaret
clojurians
clojure
that is, you can write it to an outputstream, and create the output stream in the with-open call as a second binding
2017-12-27T15:50:54.000041
Margaret
clojurians
clojure
something vaguely like `(with-open [in …. out (io/output-stream (io/file (str …)))] (.write out in))` but probably also requiring a loop or a byte count on the write
2017-12-27T15:51:50.000007
Margaret
clojurians
clojure
these files are only 60M, I'll deal with the 'memory inefficiency' then
2017-12-27T15:52:42.000323
Berry
clojurians
clojure
it’s just a needless creation of a string, not a huge deal
2017-12-27T15:53:16.000053
Margaret
clojurians
clojure
also just to be clear making a string out of a 60 meg file that’s encoded with utf-8 is likely 120megs in memory because java strings are utf-16
2017-12-27T15:57:02.000276
Margaret
clojurians
clojure
and definitely don’t use slurp/spit for anything that isn’t text
2017-12-27T15:57:50.000086
Margaret
clojurians
clojure
(I don’t know what those “images” in the name refer to just be aware that if they are image data as in bmp or jpeg slurp/spit will turn them into garbage)
2017-12-27T15:59:08.000167
Margaret
clojurians
clojure
is anyone else able to watch <https://www.youtube.com/watch?v=5VAEXYYdfWY> (“Zippers - Episode 2”)? it’s not working for me.
2017-12-27T17:49:35.000138
Alline
clojurians
clojure
oh, i get a better error message embedded here in slack, sorry! (“This video requires payment to watch”)
2017-12-27T17:50:12.000070
Alline
clojurians
clojure
is there an easy way to list the requires for a given namespace? I was looking for something like ns-refers but for requires
2017-12-27T18:29:15.000031
Barbar
clojurians
clojure
i didnt realize youtube red videos were part of regular youtube
2017-12-27T18:31:22.000029
Williemae
clojurians
clojure
I have a lot of .cljc code I'd like to make into a library. Is there a way to make cross platform libraries without rewriting my code twice?
2017-12-27T18:57:02.000002
Giovanni
clojurians
clojure
<@Giovanni> are you already using reader conditionals?
2017-12-27T19:45:01.000006
Barbar
clojurians
clojure
(<https://clojure.org/guides/reader_conditionals>)
2017-12-27T19:45:41.000076
Barbar
clojurians
clojure
Yeah I tested out my reader conditionals in a chestnut project and they worked in both runtimes.
2017-12-27T19:45:44.000044
Giovanni
clojurians
clojure
I just never actually packaged a pure cljc project. Does the default lein template work fine for both runtimes?
2017-12-27T19:46:21.000081
Giovanni
clojurians
clojure
that part i’m not sure about
2017-12-27T19:48:39.000122
Barbar
clojurians
clojure
<https://github.com/stuartsierra/component> looks like a minimal example of a (not quite pure) .cljc library
2017-12-27T19:50:18.000131
Alline
clojurians
clojure
I should have looked at Sierra's components. It never clicked that I had them on the back and the front with the same namespace. It looks like this library has a project.clj a lot like mine as well. Thanks much!
2017-12-27T19:55:03.000014
Giovanni
clojurians
clojure
hey, has anyone successfully used a go block in clojure &gt;=1.7.0? i am having trouble with it not closing over its scope properly, so `(let [c (chan)] (go (prn (&lt;! c))))` gets me `Unable to resolve var: c`
2017-12-27T20:59:38.000073
Linn
clojurians
clojure
this is right out of the tutorial, and it works in clojure 1.6
2017-12-27T20:59:55.000093
Linn
clojurians
clojure
but that seems like an awful long time for something so fundamental to be broken
2017-12-27T21:00:05.000140
Linn
clojurians
clojure
so i’m open to it being totally my problem
2017-12-27T21:00:12.000052
Linn
clojurians
clojure
the weird thing about that block of code is that core.async should treat it as a noop returning a channel that never delivers
2017-12-27T21:00:55.000085
Margaret
clojurians
clojure
since nothing can possibly use c
2017-12-27T21:01:02.000009
Margaret
clojurians
clojure
i mean, there’s a more complicated version of that code, which also fails with the same issue, which actually does do a real hello world with the channels, in the tutorial
2017-12-27T21:01:34.000024
Linn
clojurians
clojure
but i stripped it down to just that being enough for it to fail with the same issue
2017-12-27T21:01:44.000181
Linn
clojurians
clojure
```Clojure 1.9.0 +user=&gt; (require '[clojure.core.async :as &gt; :refer [go chan &lt;!]]) nil +user=&gt; (let [c (chan)] (go (prn (&lt;! c)))) #object[clojure.core.async.impl.channels.ManyToManyChannel 0x1e5e2e06 "clojure.core.async.impl.channels.ManyToManyChannel@1e5e2e06"] ```
2017-12-27T21:02:11.000137
Margaret