workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
I can't think of anything that would cause people to switch to Clojure just to use it...
2017-12-13T17:27:53.000016
Daniell
clojurians
clojure
(mind you, Akka and Play are both probably used more by Java devs now?)
2017-12-13T17:28:11.000050
Daniell
clojurians
clojure
(fn [v n] [(take n v) (drop n v)]) ^-- is there a builtin for this? to 'split' a vector at a specified index
2017-12-13T17:32:53.000426
Berry
clojurians
clojure
we have Datomic and Onyx, and of course ClojureScript, which has the obvious advantage of allowing you to avoid JS :stuck_out_tongue:
2017-12-13T17:34:57.000234
Leann
clojurians
clojure
I would presume this kind of thing can only come in later in a project then, after the patterns have emerged. That would explain why our experiences differ. I've spent more time in the greenfield part of a project, and very little time in the stage where you're extending existing code. We have a few places where we achieve something of a similar goal with data, e.g. defining schemas related to a graphql request, and allowing a small bit of code extract that. I think the scariest part of what you said was "[building] an ad-hoc engine", I don't even know where I'd start really. Reading through odin, I find terms like "unification" and "tabling" quite intimidating. I should perhaps purchase your series where you build odin to try and learn more about Karen and such.
2017-12-13T17:40:31.000476
Jodie
clojurians
clojure
<@Berry> clojure.core/split-at
2017-12-13T17:43:58.000321
Charity
clojurians
clojure
Fwiw, I really like Odin so far. I'm trying to use it for querying REST apis. I've had to put a memoize in though (I want to replace this with a ctx cache), as Odin was "forking" (my term for the separate paths after doing an additional query) queries when I didn't expect it to, as there was no overlap in the inputs. I'm not sure if I'm using it properly, or even if I'm benefiting from it. I initially reached for datalog/datascript to do this, but being unable to make arbitrary rest queries made it difficult (having to commit to a db after doing part of the query I'm interested in probably doesn't give me much benefit.
2017-12-13T17:48:15.000212
Jodie
clojurians
clojure
I'm struggling now with something in odin, which is something to the effect of: - I've fetched all members from API - I've fetched all tasks from API - I want to find the assignee of a task - I want to find the owners of a task I seem to keep filtering all the members, instead of creating a list of members named "assignee". The closest way I came to achieving my goal was `(o/and (= (:assignee_id ?task) (:id ?member))`, which obviously doesn't involve any bindings. I wondered if I'd need to use `o/==` but I wasn't certain how I'd do that.
2017-12-13T17:54:44.000023
Jodie
clojurians
clojure
also you could use subvec if you want a faster op that retains vectorness
2017-12-13T17:55:41.000571
Margaret
clojurians
clojure
```ser=&gt; (let [v [1 2 3 4 5 6]] [(subvec v 0 3) (subvec v 3 (count v))]) [[1 2 3] [4 5 6]]```
2017-12-13T17:57:22.000058
Margaret
clojurians
clojure
Maybe I should be "re-fetching" a list of members for assignees.
2017-12-13T18:07:46.000203
Jodie
clojurians
clojure
OK, probably a deep dark corner of Clojure functionality I haven't seen before, but can anyone explain what ('subset? ...) is doing in this line of code within the Clojure tests? <https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/rt.clj#L97>
2017-12-13T20:30:25.000067
Micha
clojurians
clojure
map look up
2017-12-13T20:31:13.000219
Rebeca
clojurians
clojure
looking up the symbol 'subset in the map returned by ns-publics
2017-12-13T20:31:26.000332
Rebeca
clojurians
clojure
I just figured that out from REPL experimentation, which I probably should have done before asking. I knew that worked with a keyword as the first value in the form, but don't think I've ever used it with a symbol as the first value in the form.
2017-12-13T20:32:40.000090
Micha
clojurians
clojure
<@Micha> `clojure.lang.Symbol` implements `clojure.lang.IFn` just like `clojure.lang.Keyword`, and seems to implement it in basically the same way, invoking `RT.get` on the argument passing itself as the lookup key
2017-12-13T21:20:15.000158
Buck
clojurians
clojure
I will most likely forget this, and not miss the knowledge because I wouldn't want to see this in my code :slightly_smiling_face:
2017-12-13T21:21:07.000002
Micha
clojurians
clojure
yeah it's a bit niche isn't it
2017-12-13T21:21:42.000051
Buck
clojurians
clojure
I've only ever written Clojure as a hobby, but a lot of hours have gone by without me seeing this in people's code.
2017-12-13T21:22:03.000302
Micha
clojurians
clojure
would be interesting to mine crossclj for the most rarely used features. I don't think I've ever seen :strs or :syms destructuring in the wild, for instance
2017-12-13T21:25:04.000073
Buck
clojurians
clojure
now I'm kind of sad that there's no clojure.lang.String that also implements IFn. Then we'd have three types you can both destructure and use to look themselves up.
2017-12-13T21:26:40.000013
Buck
clojurians
clojure
<@Buck> We have `:strs` destructuring in our production code... :slightly_smiling_face:
2017-12-13T21:42:48.000133
Daniell
clojurians
clojure
secretly I think I have this in my code too ...
2017-12-13T21:45:53.000204
Buck
clojurians
clojure
but it's not "in the wild" so I think I escape on a technicality. `ag` reveals I actually have used it twice in just this one project I checked :flushed:
2017-12-13T21:47:17.000148
Buck
clojurians
clojure
Spec question: If I have a function that takes a destructured map, what's the best way to spec that function, so that the values of the keys in my map are also specced? The best I've got right now is `(s/keys :req-un [::a ::b ::c])` given `(defn foo [{:keys [a b c]})`
2017-12-13T22:05:36.000199
Silas
clojurians
clojure
But, I'd kind of want the names of the keys for my function to not match the spec name of their value. And I'd rather define the spec for them inline. Any easy way to do that?
2017-12-13T22:06:05.000007
Silas
clojurians
clojure
Would be nice to have something like `(s/map :req [:a int? :b string? :c ::other-spec])` for this scenario
2017-12-13T22:16:57.000139
Silas
clojurians
clojure
Is there a way to make this point free `#(assoc %2 :id %1)`
2017-12-13T22:32:14.000228
Eugenie
clojurians
clojure
Clojure is the killer application. It sells itself, you don't really need anything else. For example, since you mentioned Akka, you'd probably be interested in core.async, though its just a part of Clojure.
2017-12-13T22:37:17.000179
Silas
clojurians
clojure
lol, I don't think it'd be shorter in any point free style
2017-12-13T22:42:39.000011
Berry
clojurians
clojure
I get that. This was a just a challenge based on a discussion we are having internally at my company.
2017-12-13T22:48:57.000223
Eugenie
clojurians
clojure
In terms of things made in Clojure to be used as frameworks from other languages, I guess <@Leann> pointed to some: Datomic and Onyx. I'll add Apache Storm, Overtone, Cascalog, Riemann, Puppet, Metabase, Alda, Transit, Datascript and Quil to that list.
2017-12-13T22:59:26.000035
Silas
clojurians
clojure
maybe something involving merge, apply, and reverse, and rotating
2017-12-13T23:06:32.000059
Berry
clojurians
clojure
(apply assoc (reverse (interpose :id %)))
2017-12-13T23:07:17.000175
Berry
clojurians
clojure
(-&gt;&gt; args (interpose :id) reverse (apply assoc)) :slightly_smiling_face:
2017-12-13T23:07:36.000070
Berry
clojurians
clojure
That's not point-free...
2017-12-13T23:07:51.000024
Daniell
clojurians
clojure
What is point-free? I thought it merely meant "don't use variable names, and chain together functions"
2017-12-13T23:08:26.000103
Berry
clojurians
clojure
But `args` and `%` are variables.
2017-12-13T23:09:45.000141
Daniell
clojurians
clojure
right, so we need to get rid of the "args" field
2017-12-13T23:10:18.000159
Berry
clojurians
clojure
the line before that was me working out intermediate steps
2017-12-13T23:10:37.000112
Berry
clojurians
clojure
we need to removeargs from `(-&gt;&gt; args (interpose :id) reverse (apply assoc))` and then we're good
2017-12-13T23:11:05.000164
Berry
clojurians
clojure
Here's a point-free version: `(comp (partial apply assoc) reverse (partial interpose :id) vector)`
2017-12-13T23:12:25.000051
Daniell
clojurians
clojure
```boot.user=&gt; ( (comp (partial apply assoc) reverse (partial interpose :id) vector) 123 {} ) {:id 123}```
2017-12-13T23:12:45.000031
Daniell
clojurians
clojure
<@Eugenie> ^ does that answer the challenge?
2017-12-13T23:15:06.000098
Daniell
clojurians
clojure
<@Daniell> Sure does! Thanks!
2017-12-13T23:17:56.000220
Eugenie
clojurians
clojure
The :clj: page on transients says that: &gt; In Clojure 1.6 and earlier, transients would detect any (read or write) use from a thread other than the one that created them and throw an exception. *That check was removed in 1.7* to allow for more flexible use in frameworks like core.async go blocks that enforce the single-threaded constraint via other means. Emphasis mine. But under summary it still says: &gt; Thread isolation - enforced I tried the following in :clj: 1.8: ``` (dotimes [_ 5] (def tv (let [tv (transient [])] (future (Thread/sleep (rand-int 3)) (conj! tv 1)) (future (Thread/sleep (rand-int 3)) (conj! tv 2)) tv)) (Thread/sleep 3) (println (persistent! tv))) ;; =&gt; ;; [2 1] ;; [2 1] ;; [2 1] ;; [2 1] ;; [1 2] ``` So it clearly _is_ possible to modify a transient from different threads. What, then, does "thread-isolation--enforced" mean? <https://clojure.org/reference/transients>
2017-12-13T23:54:10.000150
Andra
clojurians
clojure
[just guessing] perhaps it means that with respect to a transient, conj! pop! push! are all atomic -- i.e. if you run them from different threads, its as if they're beintg run from the same thread in some order - they won't 'trample' on each other due to race conditions
2017-12-14T00:22:38.000124
Berry
clojurians
clojure
also, the above example confuses me, as I thought you were supposed to look at the return value of conj! ... instead of printing the 'original transient'
2017-12-14T00:23:16.000007
Berry
clojurians
clojure
IIUC `conj!` modifies in place but returns the modified value.
2017-12-14T00:29:41.000157
Andra
clojurians
clojure
quoting: <https://clojuredocs.org/clojure.core/assoc>! ``` ;; The key concept to understand here is that transients are ;; not meant to be `bashed in place`; always use the value ;; returned by either assoc! or other functions that operate ;; on transients. ``` not sure if "other functions" includes conj!
2017-12-14T00:32:09.000152
Berry
clojurians
clojure
I'm looking for a clojure DSL that lets me output C code. Is <https://github.com/aaronc/c-in-clj> (5 years since last commit?) the best we've got ? Pre-emptive: why not just use C?: C's macro system is lacking. I want to use the full power of Clojure amcros for my macro system.
2017-12-14T00:37:13.000034
Berry
clojurians
clojure
There are several cases where conj! May not change the input, and instead may return a new collection
2017-12-14T01:25:00.000218
Sandy
clojurians
clojure
So yes, treat transients like persistent collections.
2017-12-14T01:25:11.000173
Sandy
clojurians
clojure
Not that I know of, it’s not really a easy thing to pull off since C lacks almost everything Clojure would need
2017-12-14T01:26:18.000123
Sandy
clojurians
clojure
But writing a AST to C layer wouldn’t be *that* hard. I know of several projects that do that
2017-12-14T01:26:41.000186
Sandy
clojurians
clojure
Carp? It transpiles to c so I guess it would fit
2017-12-14T01:55:34.000041
Weston
clojurians
clojure
Not sure how mature it is tho
2017-12-14T01:55:56.000096
Weston
clojurians
clojure
<@Sandy>: I'm not trying to do Clojure -&gt; C . I'm trying to do "Clojure data representing a program -&gt; C".
2017-12-14T03:17:34.000094
Berry
clojurians
clojure
I have some code which deals with nothing but tensors of floats -- no other data structure, no gc-ing, nothing else and I want to represent this code as 'clojure data', and then generate C from it (which will let me hit both WebAssembly and Cuda afterwards)
2017-12-14T03:18:30.000308
Berry
clojurians
clojure
if I'm dealing with a java class that extends a HashMap, is there an easy way to cast a map into it? ```public class RowData extends HashMap&lt;String, Object&gt; { } ```
2017-12-14T03:26:08.000338
Debby
clojurians
clojure
would love to do `(cast RowData (java.util.HashMap. {:a 1}))` but that raises a `ClassCastException`
2017-12-14T03:26:28.000361
Debby
clojurians
clojure
I'm playing with function specs and I wondered if one could use it to emulate type checking, during compile time, something like this: ``` (s/fdef divide :args (s/cat :x integer? :y integer?) :ret number?) (defn divide [x y] (/ x y)) ;; should throw when compiled? (defmacro divide-by-foo [] (eval `(divide 6 :foo))) ``` yet this namespace doesn't throw, why?
2017-12-14T05:27:57.000188
Deneen
clojurians
clojure
Interesting Idea, but probably needs some time to become doable. For example if? in the future Kotlin can compile to web-assembly it will become easier.
2017-12-14T05:48:09.000356
Daine
clojurians
clojure
Actually not that far away, <https://blog.jetbrains.com/kotlin/2017/11/kotlinnative-v0-4-released-objective-c-interop-webassembly-and-more/>
2017-12-14T05:49:05.000070
Daine
clojurians
clojure
hi guys
2017-12-14T05:55:29.000243
Mallory
clojurians
clojure
why this work in second case and not work in the first
2017-12-14T05:56:00.000091
Mallory
clojurians
clojure
?
2017-12-14T05:56:02.000205
Mallory
clojurians
clojure
<@Deneen> you need to have instrumentation enabled to have it throw
2017-12-14T06:01:12.000254
Retta
clojurians
clojure
<@Deneen> something like <https://github.com/jeaye/orchestra>
2017-12-14T06:02:02.000584
Retta
clojurians
clojure
<@Deneen> by default, clojure spec doesn't circumvent evaluation to perform spec analysis, you need to tell it to check your specs
2017-12-14T06:03:34.000103
Retta
clojurians
clojure
so just `(:require [clojure.spec.test.alpha :as st])` and `(st/instrument 'divide)` ?
2017-12-14T06:04:37.000034
Deneen
clojurians
clojure
you'll have to read over the docs, and mess around with it
2017-12-14T06:08:11.000371
Retta
clojurians
clojure
think it's after you define your specs, but before you evaluate your function that you want spec analysis for
2017-12-14T06:08:43.000317
Retta
clojurians
clojure
hmm
2017-12-14T06:09:31.000009
Retta
clojurians
clojure
your defmacro is never going to throw a spec error until it's been evaluated
2017-12-14T06:09:55.000198
Retta
clojurians
clojure
note that instrumentation was turned on after the specs have been introduced and evaluated
2017-12-14T06:12:46.000415
Retta
clojurians
clojure
(into (new RowData) my-map)? Into uses conj
2017-12-14T06:12:51.000301
Jutta
clojurians
clojure
I could have put it at line 7 or 9
2017-12-14T06:13:04.000349
Retta
clojurians
clojure
the divide-by-foo case should probably fail, none of this has been tested
2017-12-14T06:13:47.000160
Retta
clojurians
clojure
<@Daine>: I think we are discussing different problems. What problem do you think I am trying to solve?
2017-12-14T06:20:52.000483
Berry
clojurians
clojure
this is my problem - I don't understand why at compile-time the macro doesn't become `(eval (/ 6 :foo))`, which should still throw. The divide-by-foo will fail for sure (with an exception or spec validation error depending on whether instrumentation is turned on), like you say.
2017-12-14T06:21:28.000099
Deneen
clojurians
clojure
if i want to display some quick charts from the repl, is incanter the best option?
2017-12-14T06:26:45.000468
Jena
clojurians
clojure
i just want to quickly visualize some line charts, no fancy processing is needed
2017-12-14T06:27:15.000203
Jena
clojurians
clojure
Does either "lein repl" or "boot repl" have a web interface? I want something like "boot web-repl" or "lein web-repl" to 1. open up a webserver on port 8081 2. I can go to <localhost://8081> and interact with the repl 3. have certain forms of output render nicely into HTML tables / SVG diagrams / ...
2017-12-14T06:32:27.000121
Berry
clojurians
clojure
You want some way to go from clojure to WebAssembly right?
2017-12-14T06:34:07.000355
Daine
clojurians
clojure
You can do a plug-in with it <https://github.com/yudai/gotty>
2017-12-14T06:36:31.000100
Jutta
clojurians
clojure
<@Berry> gorilla repl can do that
2017-12-14T06:37:30.000094
Angela
clojurians
clojure
<http://gorilla-repl.org/start.html>
2017-12-14T06:37:43.000011
Angela
clojurians
clojure
or to CUDA which kinda makes it invalid approach to go for Kotlin
2017-12-14T07:01:26.000397
Cecilia
clojurians
clojure
Can you run CUDA in the browser?
2017-12-14T07:22:07.000085
Daine
clojurians
clojure
is there a tool for formatting end files?
2017-12-14T07:22:24.000099
Danille
clojurians
clojure
<https://github.com/weavejester/cljfmt>
2017-12-14T07:48:48.000208
Maggie
clojurians
clojure
.. why did I not just try running cljfmt on it earlier. I keep running it on my .clj files
2017-12-14T07:49:52.000190
Danille
clojurians
clojure
thanks :slightly_smiling_face:
2017-12-14T07:49:54.000432
Danille
clojurians
clojure
Hi, I am transducing over a lazy sequence that reads from a file (hurray). However I am having some trouble figuring efficient ways to debug or any plausible way to debug at all. Maybe you can comment? Here's code: ``` (ns cleanser.dictionary-test (:require [clojure.pprint :refer [pprint]] [puget.printer :refer [cprint]] [clojure.inspector :as inspect :refer [inspect-tree]] [cleanser.dictionary-search :refer :all] [<http://clojure.java.io|clojure.java.io> :as io] [clojure.set :refer :all] [clojure.math.combinatorics :refer [cartesian-product]] [clojure.test :refer :all] [<http://clojure.java.io|clojure.java.io> :as io] [clojure.string :refer [split]])) (defn text-file-reader [filepath reader] " return a lazy sequence for streaming through the file contents " (with-open [file-reader (reader filepath)] (line-seq file-reader))) (deftest names-dictionary (let [text (slurp "resources/names/hebrew-wikipedia-content.txt") names-dump-filter (remove #(re-matches #"# &lt; &gt; \[ \] \{ \} / @ \*" %)) names-dump-breaker (mapcat #(split % #"\|")) names (sequence (comp names-dump-breaker names-dump-filter) (text-file-reader "resources/names/user-names-unique.txt" <http://clojure.java.io/reader|clojure.java.io/reader>)) dictionary (build-dictionary names)] (println (search text dictionary)) (println (type names) ; a lazy stream (println names)))) ; java.io.IOException: Stream closed ``` printing `names` seems futile, the stream has been expended by then. Any suggestion for a better design for stream-processing file contents with transducers? Any best practice for debugging within the transduction itself is very welcome as well Many thanks!
2017-12-14T08:19:00.000070
Kalyn
clojurians
clojure
<@Kalyn> you could use trace to monitor the input/output of your transducer functions <https://github.com/clojure/tools.trace>
2017-12-14T08:23:17.000223
Jami
clojurians
clojure
actually, I am not very sure how I'd `trace` very elegantly in transducing code like above
2017-12-14T08:30:36.000337
Kalyn
clojurians
clojure
<@Kalyn> I though it would be easy with trace, but it doesn't work as expected in my case
2017-12-14T09:25:12.000773
Jami
clojurians
clojure
instead, you could define your own transducer for logging purpose
2017-12-14T09:25:29.000325
Jami
clojurians
clojure
``` (defn xflog [] (fn [rf] (fn ([] (rf)) ([res] (rf result)) ([res input] (println input) (rf res input))))) ```
2017-12-14T09:26:09.000134
Jami