workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
I had a hunch that constantly obviates the need for a macro that creates a do form ```+user=> (def foo (constantly :OK)) #'user/foo +user=> (foo (println :a) (println :b) (println :c)) :a :b :c :OK ```
2017-11-02T18:14:34.000006
Margaret
clojurians
clojure
I wonder if it still works for large arg lists
2017-11-02T18:14:45.000124
Margaret
clojurians
clojure
oh yeah, constantly creates a functions that accepts any number of arguments. that invalidates my argument to prefer it over the macro form
2017-11-02T18:45:12.000251
Ahmad
clojurians
clojure
I do not understand what the `n` argument does in practice in `pipeline-async` 0_o
2017-11-02T19:03:53.000016
Aldo
clojurians
clojure
How do I use apply with a Java object?
2017-11-02T19:04:40.000047
Alix
clojurians
clojure
I want to call a method on a java object using the apply function. Is this possible?
2017-11-02T19:04:55.000048
Alix
clojurians
clojure
How do I call a java method with potentially different number of arguments?
2017-11-02T19:05:16.000231
Alix
clojurians
clojure
<@Alix> afaik not without explicitly using reflection
2017-11-02T19:06:19.000121
Aldo
clojurians
clojure
and even if you could figure out how to do it implicitly... it would still be expensive
2017-11-02T19:06:40.000295
Aldo
clojurians
clojure
How expensive is reflection?
2017-11-02T19:07:01.000095
Alix
clojurians
clojure
quite a few orders of magnitude more expensive than a regular function call
2017-11-02T19:07:23.000275
Aldo
clojurians
clojure
but, if you're in a context where you're doing io... not at all
2017-11-02T19:07:35.000013
Aldo
clojurians
clojure
bfabry: <https://dev.clojure.org/jira/browse/ASYNC-163?focusedCommentId=42480&amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-42480>
2017-11-02T19:16:32.000005
Rebeca
clojurians
clojure
ta, sounds like what I thought. practically it's only a limit if tasks are completing and sending results
2017-11-02T19:22:46.000328
Aldo
clojurians
clojure
so, let’s say I have used reify on an interface and it closes over on of my Clojure functions. At the REPL, I want to be able to redefine my fn and have the reified object call it. I assume a layer of indirection will do the trick, but what is the best way to achieve this? Use resolve first to get the fn and then invoke it?
2017-11-02T21:26:28.000025
Tammie
clojurians
clojure
<@Tammie> call the functions like this `(#'foo x y)` instead of `(foo x y)`
2017-11-02T21:46:45.000074
Sandy
clojurians
clojure
Although vars work that way already
2017-11-02T21:47:08.000045
Sandy
clojurians
clojure
how do I express the following in clojure: 1. I have a job queue with 1000 items 2. I have 12 worker threads 3. whenever a worker thread finishes a job, it pops off the next job from the queue, and executes it
2017-11-02T21:59:00.000151
Berry
clojurians
clojure
Java has an ExecutorService that is a great match for this but you would use interop for it
2017-11-02T22:20:07.000100
Sonny
clojurians
clojure
Maybe this? <https://github.com/TheClimateCorporation/claypoole/blob/master/README.md>
2017-11-02T22:20:11.000050
Kyung
clojurians
clojure
Or use that ^^
2017-11-02T22:20:18.000055
Sonny
clojurians
clojure
Which is a Clojurey wrapper for it
2017-11-02T22:20:45.000195
Sonny
clojurians
clojure
<https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html>
2017-11-02T22:20:48.000148
Berry
clojurians
clojure
I'm using the ExecutorService. How do I call 'sxubmit' on a clojure function? The problem is that it appears to match both Collable and Runnable ... (fn [] ...)
2017-11-02T22:21:13.000030
Berry
clojurians
clojure
Add a type hint to disambiguate
2017-11-02T22:22:04.000035
Sonny
clojurians
clojure
ah, <https://groups.google.com/forum/#!topic/clojure/MDAIeDDq--8>
2017-11-02T22:22:06.000011
Berry
clojurians
clojure
^Runnable
2017-11-02T22:22:16.000043
Sonny
clojurians
clojure
(def #^Runnable r (proxy [Runnable] [] (run [] (rand)))) &lt;-- does your solution avoid the 'proxy' ?
2017-11-02T22:22:35.000212
Berry
clojurians
clojure
You don’t need a proxy
2017-11-02T22:23:28.000114
Sonny
clojurians
clojure
``` (.submit service ^Runnable (fn [] ...)) ``` appears to work
2017-11-02T22:23:31.000153
Berry
clojurians
clojure
Yeah
2017-11-02T22:23:37.000062
Sonny
clojurians
clojure
All Clojure functions are Runnable
2017-11-02T22:23:59.000178
Sonny
clojurians
clojure
everything works now; thanks for help
2017-11-02T22:24:50.000066
Berry
clojurians
clojure
in The Joy of Clojure there's a passage stating: &gt; Clojure functions are highly amenable to interoperability. Their underlying classes implement a number of useful interfaces does it means that the Clojure compiler wraps Clojure functions into Java classes that under the hood implement some interfaces or something like that?
2017-11-02T23:03:02.000158
Ahmad
clojurians
clojure
qqq's message reminded me of it
2017-11-02T23:04:42.000090
Ahmad
clojurians
clojure
<@Ahmad> Yes, each function is compiled to a class with a number of methods.
2017-11-02T23:12:26.000189
Daniell
clojurians
clojure
<@Ahmad> Here's the ancestors of a function type: ```boot.user=&gt; (defn foo [x] (inc x)) #'boot.user/foo boot.user=&gt; (class foo) boot.user$foo boot.user=&gt; (ancestors *1) #{java.util.Comparator clojure.lang.AFunction clojure.lang.IMeta java.io.Serializable clojure.lang.Fn java.lang.Runnable java.util.concurrent.Callable clojure.lang.IFn java.lang.Object clojure.lang.AFn clojure.lang.IObj}``` The function compiles to a class called, in this case, `boot.user$foo` (an inner class `foo` in the `boot.user` class which the namespace is compiled to), and it extends/implements all of those listed classes.
2017-11-02T23:16:15.000115
Daniell
clojurians
clojure
<@Daniell> Interesting, so the namespace is also compiled into a class, at least that's what it seems from your example. Does it mean that if I was to create a namespace with `gen-class` its methods would be defined in the `boot.user` class for example and not in an inner class?
2017-11-02T23:19:51.000116
Ahmad
clojurians
clojure
The methods would be defined in the class of the namespace yes (and `gen-class` lets you specify the class name if you want a different one).
2017-11-02T23:22:18.000082
Daniell
clojurians
clojure
It's why the default application you often see has a `(gen-class)` in `whatever/core.clj` and a `-main` function -- and that's compiled to a `whatever.core` class with a `main` method (the `-` is the default convention for `gen-class`).
2017-11-02T23:24:04.000052
Daniell
clojurians
clojure
Woah, I didn't know that, `-main` makes sense for me now :D
2017-11-02T23:25:25.000071
Ahmad
clojurians
clojure
Thanks for your explanations <@Daniell>!
2017-11-02T23:25:46.000031
Ahmad
clojurians
clojure
Also note that anonymous functions get compiled to "unique" class names ```boot.user=&gt; (defn quux [n] (fn [m] (* m n))) #'boot.user/quux boot.user=&gt; (def times2 (quux 2)) #'boot.user/times2 boot.user=&gt; (type times2) boot.user$quux$fn__1879```
2017-11-02T23:28:05.000029
Daniell
clojurians
clojure
In this case `quux` is compiled to an inner class inside `boot.user`, and the anonymous function is compiled to an inner class called `fn__1879` inside the `quux` inner class.
2017-11-02T23:29:01.000074
Daniell
clojurians
clojure
Nice, it gets deeper and deeper.
2017-11-02T23:29:56.000007
Ahmad
clojurians
clojure
Functions, all the way down :slightly_smiling_face:
2017-11-02T23:30:03.000128
Daniell
clojurians
clojure
:)
2017-11-02T23:30:12.000022
Ahmad
clojurians
clojure
I’m trying to solve an issue we have testing a largish project with `lein test`; occasionally the test run halts with `Tests failed. Error encountered performing task ‘test’ with profile(s): ‘base,system,user,provided,dev,humane-errors’ Tests failed.`
2017-11-03T10:27:46.000549
Karolyn
clojurians
clojure
I just cannot get it to be more verbose than that. We’re running this on CircleCI in a docker container and the last test namespace to run seems to be one that contains some clojure.spec generative tests
2017-11-03T10:29:26.000402
Karolyn
clojurians
clojure
other than that no clue. Does anyone have any idea on how I can figure out which test in the test namespace was the last one run or any idea on what the problem might be?
2017-11-03T10:30:45.000222
Karolyn
clojurians
clojure
<@Karolyn> you can log test names by redefining `report :begin-test-var` method: <https://gist.github.com/metametadata/c40a5f099814e591cd627b874f9bb595#file-reporter-clj-L14>
2017-11-03T11:30:09.000764
Adele
clojurians
clojure
oh nice thanks!
2017-11-03T11:38:04.000194
Karolyn
clojurians
clojure
Is there any idiomatic way of getting a map from a sequence of keys (with a value associated with each key based on the key)?
2017-11-03T14:11:40.000053
Earlie
clojurians
clojure
``` (into {} (map (fn [a] [a (derived-value a)]) [:alpha :bravo :charlie :delta :echo])) ```
2017-11-03T14:13:00.000204
Earlie
clojurians
clojure
I suppose you could replace that `fn` with `(juxt identity derived-value)` but that’s not necessarily any better
2017-11-03T14:17:14.000253
Shamika
clojurians
clojure
Huh, I hadn't thought about that. Thanks
2017-11-03T14:17:59.000204
Earlie
clojurians
clojure
into takes a transducer theses days
2017-11-03T14:19:46.000422
Rebeca
clojurians
clojure
`(into {} (map (juxt ...)) ...)`
2017-11-03T14:20:06.000512
Rebeca
clojurians
clojure
<@Rebeca> Nice, that is pretty concise. `(into {} (map (juxt identity (partial str :test))) [:a :b :c])`
2017-11-03T14:21:24.000152
Earlie
clojurians
clojure
`(zipmap a (map derived-value a))`
2017-11-03T14:40:54.000515
Sonny
clojurians
clojure
?
2017-11-03T14:40:56.000296
Sonny
clojurians
clojure
<@Sonny> That certainly works, though I was looking for something that doesn't repeat a or require binding it.
2017-11-03T14:42:29.000352
Earlie
clojurians
clojure
`(apply zipmap ((juxt identity #(map derived-value %)) a))`
2017-11-03T14:45:38.000460
Sonny
clojurians
clojure
<@Sonny> That is quite nice.
2017-11-03T14:47:22.000711
Earlie
clojurians
clojure
that’s awful :)
2017-11-03T14:47:29.000363
Sonny
clojurians
clojure
I’d use zipmap :)
2017-11-03T14:47:33.000216
Sonny
clojurians
clojure
Which is awful? :stuck_out_tongue:
2017-11-03T14:48:04.000402
Earlie
clojurians
clojure
the apply / juxt version
2017-11-03T14:48:12.000485
Sonny
clojurians
clojure
the simple zipmap one is far and away the clearest of these imo
2017-11-03T14:48:35.000393
Sonny
clojurians
clojure
Yeah, I'd agree.
2017-11-03T14:49:00.000118
Earlie
clojurians
clojure
<@Sonny> Good call; zipmap feels cleaner in my actual use case as well.
2017-11-03T14:52:40.000065
Earlie
clojurians
clojure
(Compared to into/map/juxt)
2017-11-03T14:52:52.000465
Earlie
clojurians
clojure
unfortunately, the implementation of zipmap is not as fast as it could be atm, although in the majority of cases you won’t have enough data for it to make any difference
2017-11-03T14:53:21.000333
Sonny
clojurians
clojure
Yeah, there's only 7 keywords.
2017-11-03T14:53:41.000187
Earlie
clojurians
clojure
Good to know though.
2017-11-03T14:53:47.000320
Earlie
clojurians
clojure
I prefer the zipmap, though I want to give lip-service to `medley.core` which has `map-vals` to get rid of the the `(into {} (map...` nastiness, such as ```(map-vals derived-value (zipmap a a))``` It's an extra step, but separating the steps of creating a self-keyed map might be a helpful pattern elsewhere
2017-11-03T14:55:38.000165
Cecile
clojurians
clojure
oh sure, I agree that’s the intent
2017-11-03T14:56:08.000595
Sonny
clojurians
clojure
I wish we had map-keys / map-vals in core
2017-11-03T14:56:39.000520
Sonny
clojurians
clojure
Out of curiosity, why don't we?
2017-11-03T14:58:55.000006
Adelaida
clojurians
clojure
b/c we consider new things for core somewhat rarely and I haven’t gathered the evidence to make a compelling case yet :)
2017-11-03T15:04:01.000476
Sonny
clojurians
clojure
<https://dev.clojure.org/jira/browse/CLJ-1959>
2017-11-03T15:04:32.000277
Sonny
clojurians
clojure
Fair enough. :simple_smile: Ah, thanks for the link, that was my next question.
2017-11-03T15:04:45.000280
Adelaida
clojurians
clojure
vote away :)
2017-11-03T15:05:51.000277
Sonny
clojurians
clojure
Done!
2017-11-03T15:06:57.000085
Adelaida
clojurians
clojure
-&gt; <https://twitter.com/pesterhazy/status/926529085458837505>
2017-11-03T15:19:26.000004
Fe
clojurians
clojure
I wrote map-keys into tools.deps.alpha this week :)
2017-11-03T15:20:12.000154
Sonny
clojurians
clojure
just seeing this, but my 2c — I happened to write map-keys, map-vals, and, just a couple days ago, map-kv in a utils library <@Sonny>
2017-11-03T15:30:27.000299
Larissa
clojurians
clojure
where `map-kv` takes a function of arity-2
2017-11-03T15:30:39.000401
Larissa
clojurians
clojure
oh sure, there are lots of them out there :)
2017-11-03T15:30:42.000297
Sonny
clojurians
clojure
```(ImageIO/write (BufferedImage. 10 10 BufferedImage/TYPE_USHORT_GRAY) "jpg" (<http://clojure.java.io/file|clojure.java.io/file> "test.jpg")) ``` ^-- this returns `false` . How do I debug this ?
2017-11-03T15:31:04.000305
Berry
clojurians
clojure
I'm attempting to call some Clojure code from a Java project. It seems that when I attempt to do an "import clojure.java.api.Clojure;", it succeeds when I'm pulling org.clojure/clojure 1.7.0 (via Maven), but fails when I pull org.clojure/clojure 1.8.0 since the Clojure class apparently no longer exists. Has this Clojure class been deprecated/moved? (or is there a better way to call Clojure code from Java?)
2017-11-03T15:31:39.000001
Lisette
clojurians
clojure
specter also has MAP-VALS and MAP-KEYS navigators
2017-11-03T15:31:43.000421
Aldo
clojurians
clojure
I suppose I should clarify that my goal is to call code from a library written in Clojure -- so I may be barking up the wrong tree with my approach.
2017-11-03T15:33:02.000431
Lisette
clojurians
clojure
<@Lisette> see <https://clojure.org/reference/java_interop> Calling Clojure From Java
2017-11-03T15:33:30.000170
Shira
clojurians
clojure
the docs say you should use clojure.java.api.Clojure - I don’t see why it wouldn’t find that with 1.8 so I suspect something else is wrong
2017-11-03T15:34:41.000081
Margaret
clojurians
clojure
and I can verify I’ve used clojure 1.8 via clojure.java.api.Clojure in java code
2017-11-03T15:34:56.000249
Margaret
clojurians
clojure
Those are the docs I worked with initially (and then searched around to find some people with the import statements as well)
2017-11-03T15:35:25.000460
Lisette
clojurians
clojure
Hmm. Knowing that it's working for you with 1.8 should be helpful -- maybe I'll just have to wipe my .m2 repo
2017-11-03T15:35:47.000070
Lisette
clojurians
clojure
it is odd that it has only worked for me when I'm pulling 1.7
2017-11-03T15:36:05.000135
Lisette
clojurians
clojure
hey all, can I ask a very n00b clojure question?
2017-11-03T15:36:20.000372
Floretta