workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
instead of `(to-array ...)`, I need `(into-array Pointer ...)`
2017-12-20T16:28:15.000418
Berry
clojurians
clojure
right, you need into-array
2017-12-20T16:41:33.000570
Margaret
clojurians
clojure
is `to-array` basically `(into-array Object ...)` ?
2017-12-20T17:41:30.000427
Berry
clojurians
clojure
as I understand it yes
2017-12-20T17:44:18.000389
Margaret
clojurians
clojure
except more efficient
2017-12-20T17:47:12.000418
Kareen
clojurians
clojure
<@Berry> for questions like those I suggest just looking at the sources btw, it takes about 20 seconds and you'll learn much more
2017-12-20T17:48:37.000295
Kareen
clojurians
clojure
g’day
2017-12-20T18:56:48.000353
Marcel
clojurians
clojure
i also have a small question using the thread-last macro, can I make an exception for one of the elements and insert the result as first argument?
2017-12-20T19:02:21.000207
Marcel
clojurians
clojure
I tried to wrap it in a #(myfunc % params) but it doesn’t seem to work; neither does a fn :disappointed:
2017-12-20T19:02:56.000191
Marcel
clojurians
clojure
I ended up writing an extra function outside of the thread
2017-12-20T19:03:15.000169
Marcel
clojurians
clojure
hm, I guess I misunderstood thread macros; they take the functions as partials and appends an extra argument before actually calling the function? using other macros as functions might break the thread macros…
2017-12-20T19:07:38.000253
Marcel
clojurians
clojure
maybe use the `as-&gt;` macro?
2017-12-20T19:10:08.000113
Thu
clojurians
clojure
nah, looks weird :slightly_smiling_face:
2017-12-20T19:10:21.000085
Marcel
clojurians
clojure
but is my assumption correct? (if someone understands my writing…)
2017-12-20T19:10:44.000065
Marcel
clojurians
clojure
it doesn’t create partials
2017-12-20T19:12:00.000056
Jonas
clojurians
clojure
it rewrites the code
2017-12-20T19:12:05.000113
Jonas
clojurians
clojure
so you can use the anonymous functions, but it often requires extra parens
2017-12-20T19:12:25.000043
Jonas
clojurians
clojure
yep
2017-12-20T19:12:50.000302
Marcel
clojurians
clojure
```(-&gt; [1 2 3 4] (-&gt;&gt; (map #(+ 10 %)) (map str) (clojure.string/join ",")) (clojure.string/replace #"," "."))```
2017-12-20T19:13:09.000119
Jonas
clojurians
clojure
pardon the terrible example
2017-12-20T19:13:34.000182
Jonas
clojurians
clojure
hm, I didn’t mean “real” partials… but I think I understand now why it didn’t work
2017-12-20T19:13:40.000006
Marcel
clojurians
clojure
you can “embed” thread last in a thread first
2017-12-20T19:13:47.000046
Jonas
clojurians
clojure
but not the other way around
2017-12-20T19:13:54.000102
Jonas
clojurians
clojure
you can also use the anonymous functions with extra parens
2017-12-20T19:14:18.000241
Jonas
clojurians
clojure
```(-&gt;&gt; [1 2 3 4] (map #(+ 10 %)) (map str) (clojure.string/join ",") (#(clojure.string/replace % #"," ".")))```
2017-12-20T19:14:40.000214
Jonas
clojurians
clojure
ah
2017-12-20T19:14:54.000065
Marcel
clojurians
clojure
you can also use the `as-&gt;` macro
2017-12-20T19:14:58.000212
Jonas
clojurians
clojure
woah, the extra parentheses did the trick :slightly_smiling_face: thanks
2017-12-20T19:15:40.000137
Marcel
clojurians
clojure
i’ve also seen folks write ```(-&gt; [1 2 3 4] (-&gt;&gt; (map #(+ 10 %))) (-&gt;&gt; (map str)) (-&gt;&gt; (clojure.string/join ",")) (clojure.string/replace #"," "."))```
2017-12-20T19:15:52.000008
Jonas
clojurians
clojure
I think I finally started understanding clojure today :slightly_smiling_face:
2017-12-20T19:16:08.000020
Marcel
clojurians
clojure
``` (-&gt;&gt; (apply concat (vals js)) (reduce reducer {}) (#(json/encode %1 {:pretty true})) (spit "extract.json"))) ```
2017-12-20T19:16:39.000244
Marcel
clojurians
clojure
i’m still not sure which form I prefer
2017-12-20T19:16:39.000267
Jonas
clojurians
clojure
this works
2017-12-20T19:16:49.000062
Marcel
clojurians
clojure
:thumbsup:
2017-12-20T19:16:53.000185
Jonas
clojurians
clojure
another variant ```(-&gt; [1 2 3 4] (-&gt;&gt; (map #(+ 10 %)) (map str) (clojure.string/join ",")) (clojure.string/replace #"," "."))```
2017-12-20T19:21:25.000151
Margaret
clojurians
clojure
showing that it’s not partial application ```=&gt; (-&gt; [a 1 b 41] (let (+ a b))) 42```
2017-12-20T19:22:39.000312
Margaret
clojurians
clojure
it’d be neat if there was an `as-&gt;` and `as-&gt;&gt;` that defaulted to thread-first or thread-last if no `$` was found
2017-12-20T19:23:01.000032
Thu
clojurians
clojure
I'm really tripped up on this java interop issue: I want it to call `remove(int index)` -- what would I have to do to typehint this correctly? This is the class: <https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/RedirectLocations.html> I tried to create a function ``` (defn do-it [^org.apache.http.impl.client.RedirectLocations redirect-locations ^Integer index] (.remove redirect-locations index)) ```
2017-12-20T19:24:49.000281
Danielle
clojurians
clojure
for some methods you might need to call `int` to cast the arg, recall that in clojure `1` is not an Integer, it’s a Long
2017-12-20T19:26:32.000147
Margaret
clojurians
clojure
right, so i'd wrap `index` with `(int index)` -- I tried that, still doesn't work
2017-12-20T19:28:42.000096
Danielle
clojurians
clojure
what error are you getting?
2017-12-20T19:28:51.000024
Margaret
clojurians
clojure
<@Margaret> just tried to understand your example from above… it wouldn’t work with `(-&gt;&gt; X (-&gt; Y) Z)` right?
2017-12-20T19:29:03.000043
Marcel
clojurians
clojure
<@Marcel> correct - all the other arrow macros nest inside -&gt;, but -&gt; can’t nest inside -&gt;&gt;
2017-12-20T19:29:31.000155
Margaret
clojurians
clojure
it has to do with the mechanics of the code rewrite (the silly example with the let is to show that it isn’t smart at all - it’s just moving tokens around in lists)
2017-12-20T19:30:16.000327
Margaret
clojurians
clojure
i see :upside_down_face:
2017-12-20T19:30:16.000336
Marcel
clojurians
clojure
<@Margaret> I'm not getting an error, but it's returning a boolean false which is coming from the other method signature. boolean remove(URI uri)
2017-12-20T19:30:20.000095
Danielle
clojurians
clojure
<@Danielle> ahh - what if you hint ^int instead of ^Integer?
2017-12-20T19:30:57.000152
Margaret
clojurians
clojure
(I bet I have a project with this dep, I’ll see if I can replicate in a repl)
2017-12-20T19:31:31.000034
Margaret
clojurians
clojure
how do i typehint with `^int`, i get `Unmatched delimiter: )`
2017-12-20T19:32:37.000020
Danielle
clojurians
clojure
don't do that, do `(.remove redirect-locations (int index))`
2017-12-20T19:33:40.000181
Rebeca
clojurians
clojure
err
2017-12-20T19:33:45.000094
Rebeca
clojurians
clojure
(without the extra i)
2017-12-20T19:34:02.000186
Rebeca
clojurians
clojure
```kingfisher.core=&gt; (defn rm [^RedirectLocations r ^long idx] (.remove r idx)) #'kingfisher.core/rm kingfisher.core=&gt; (rm red 0) #object[java.net.URI 0x2a3988c0 "<http://google.com>"]```
2017-12-20T19:34:16.000201
Margaret
clojurians
clojure
interesting that you typehinted a long
2017-12-20T19:35:02.000236
Danielle
clojurians
clojure
`(set! *warn-on-reflection* true)` will tell you if the compiler is emitting reflection
2017-12-20T19:35:10.000240
Rebeca
clojurians
clojure
int primitives are not supported by the clojure compiler
2017-12-20T19:35:23.000196
Margaret
clojurians
clojure
so I made it a long, and it worked
2017-12-20T19:35:31.000023
Margaret
clojurians
clojure
or just call `int`
2017-12-20T19:35:46.000196
Rebeca
clojurians
clojure
<@Rebeca> it was still calling the wrong method when I called int
2017-12-20T19:35:59.000272
Margaret
clojurians
clojure
I doubt
2017-12-20T19:36:41.000130
Rebeca
clojurians
clojure
```kingfisher.core=&gt; (defn rm2 [r idx] (.remove r (int idx))) #'kingfisher.core/rm2 kingfisher.core=&gt; (.add red 0 (java.net.URI. "<http://google.com>")) nil kingfisher.core=&gt; (rm2 red 0) false```
2017-12-20T19:37:00.000076
Margaret
clojurians
clojure
boolean is what the Object overload returns if it gets hit
2017-12-20T19:37:23.000194
Margaret
clojurians
clojure
you aren't hinting r
2017-12-20T19:37:53.000343
Rebeca
clojurians
clojure
i tried using `(int x)` instead of the typehint and it worked as well
2017-12-20T19:37:56.000162
Danielle
clojurians
clojure
you need to do both
2017-12-20T19:37:59.000088
Rebeca
clojurians
clojure
<@Rebeca> ahh, OK
2017-12-20T19:38:05.000049
Margaret
clojurians
clojure
it appeared typehinting `r` was the thing i missed
2017-12-20T19:38:05.000189
Danielle
clojurians
clojure
turning on reflection warnings will make it clear when you have eliminated the reflection or not
2017-12-20T19:38:56.000014
Rebeca
clojurians
clojure
the long hint also causes the function to implement the primitive invoke stuff(if I recall), which is orthogonal to compiling an invoke of the right method
2017-12-20T19:40:57.000261
Rebeca
clojurians
clojure
thank you gents -- i need to practice up my interop &amp; reflection fu
2017-12-20T19:41:16.000185
Danielle
clojurians
clojure
something that’s helpful sometimes is a leiningen plugin called no.disassemble - it can expose what your function compiles down to as readable mnemonics for the byte code <https://github.com/gtrak/no.disassemble>
2017-12-20T19:44:36.000346
Margaret
clojurians
clojure
Upgrading to clj 1.9. Anyone else getting these error messages? ```WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer.utils, being replaced by: #'clojure.tools.analyzer.utils/boolean? WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer, being replaced by: #'clojure.tools.analyzer.utils/boolean? WARNING: bounded-count already refers to: #'clojure.core/bounded-count in namespace: clojure.core.async, being replaced by: #'clojure.core.async/bounded-count``` ?
2017-12-20T20:10:44.000003
Malissa
clojurians
clojure
have you upgrade core.async recently?
2017-12-20T20:18:37.000040
Rebeca
clojurians
clojure
are you using require :all or use?
2017-12-20T20:19:43.000193
Rebeca
clojurians
clojure
my guess would be you have an older version of core.async that doesn't exclude bounded-count from clojure.core
2017-12-20T20:21:41.000290
Rebeca
clojurians
clojure
<@Rebeca> I have upgraded core.async, currently running on `[org.clojure/core.async "0.3.465"]`
2017-12-20T20:48:32.000183
Malissa
clojurians
clojure
This is the ns def in the file in question: ```(:require [clojure.test :refer :all] [amazonica.core :refer [defcredential]] ;; our stuff [com.stuartsierra.component :as component] [clojure.core.async :as async :refer [go go-loop &gt;! &lt;! timeout alts! alts!!]])```
2017-12-20T20:49:44.000291
Malissa
clojurians
clojure
It is having issues on my call to `go-loop` but I'm not quite so sure why
2017-12-20T20:50:30.000089
Malissa
clojurians
clojure
It appears I just needed to run lein clean :confused:
2017-12-20T20:58:37.000160
Malissa
clojurians
clojure
Appreciate the time and thoguht <@Rebeca>
2017-12-20T21:08:42.000013
Malissa
clojurians
clojure
<@Kareen>: yeah, I can definitely do a bit more clojure source reading. How do you find the source? checking out clojure + grep, or the github interface, or repl/source, or ... ?
2017-12-20T21:35:00.000006
Berry
clojurians
clojure
open your favourite IDE, type a method, click on “go to source” or similar
2017-12-20T21:51:45.000073
Marcel
clojurians
clojure
or use REPL with `(source SOME-COMMAND)`, but it’s not really useful to “browse”
2017-12-20T21:52:33.000152
Marcel
clojurians
clojure
eek
2017-12-21T00:49:30.000083
Marcel
clojurians
clojure
<@Sandy>: re parsing / ometa : I figured out what I was looking for -- parsec
2017-12-21T02:38:28.000002
Berry
clojurians
clojure
Hello all, I'm developing a reporting generator but in Java/Clojure I do not have the right library for the charting session. The charting library is in javascript, so, is there possible to generate the charts from javascript/html and use it in Clojure as svg or image without having server/browser generating it?
2017-12-21T03:41:29.000133
Lois
clojurians
clojure
<@Lois> you have the option of using nodejs or rhino to run JS without a browser
2017-12-21T04:26:45.000278
Jami
clojurians
clojure
how cheap/expensive is `(fn [] ...)` is it as cheap as a function call, or is creating anonyous functions at runtime realy expensive ?
2017-12-21T04:45:46.000255
Berry
clojurians
clojure
it is as cheap as an object creation can be
2017-12-21T04:51:44.000335
Rosia
clojurians
clojure
naively it seems for a `(fn [] ...)` there is some compilation / byte code generation to be done, which might make it expensive
2017-12-21T04:57:45.000122
Berry
clojurians
clojure
does clojure somehow do all this pre-emptively and cache it (despite not having the environment until runtime)
2017-12-21T04:58:01.000263
Berry
clojurians
clojure
each function generates a class at compile time
2017-12-21T04:58:45.000219
Rosia
clojurians
clojure
then it is lazily loaded by the classloader as with java
2017-12-21T04:59:43.000076
Rosia
clojurians
clojure
this is a drastic oversimplification, so you're saying: 1. at compile time, each `(fn [...] ...)` has a class generated for it 2. at runtime, when to exec the code, the corresponding code is passsed the env as an argument, creating a "clojure function object" 3. this "function object" can then be used just like any other clojure functions, and passed arguments to make it work ?
2017-12-21T05:01:15.000195
Berry
clojurians
clojure
yes
2017-12-21T05:03:34.000071
Rosia
clojurians
clojure
thanks; this explains so much!
2017-12-21T05:06:10.000002
Berry
clojurians
clojure
I learned a lot about the compiler by decompiling my clojure code
2017-12-21T05:07:48.000279
Rosia
clojurians
clojure
I tried that once, but the decompiler lib crashed the JVM, and I never tried it again.
2017-12-21T05:15:27.000123
Berry
clojurians
clojure
Where is the linux installer versioned? (If at all)
2017-12-21T06:54:03.000192
Jodie
clojurians
clojure
(For the clj command line tool)
2017-12-21T06:55:26.000048
Jodie