workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | at worse it can cause the compiler to crash | 2017-12-11T10:16:40.000453 | Kareen |
clojurians | clojure | Is there any handy function in Java or Clojure to coerce numbers *and* strings to long? We're parsing json, and there are fields we know are numerical, but sometimes they're strings and sometimes they're raw numbers. The json lib (Cheshire) converts the raw numbers to Integer, not Long, so we then can't use `(Long. ...)` on that, but equally `(long ...)` doesn't work when the value is a String rather than a number | 2017-12-11T10:22:20.000097 | Mallie |
clojurians | clojure | One minor question:
1:
```
(defn f [[x y z]]
(apply + [x y z]))
```
2:
```
(defn f [[x y z]]
(+ x y z))
```
why does Clojure give an uncheked warning on the last one, but not the first? | 2017-12-11T10:27:32.000407 | Johana |
clojurians | clojure | `Long/valueOf`? <@Mallie> | 2017-12-11T10:27:40.000073 | Randee |
clojurians | clojure | Since you mention “developing”, it seems to me that you want to communicate the (eventually shared) _mental model_ of the project. I remember reading an article on the need for this, and how different mental models over time cause problems or technical debt, but can’t find it. | 2017-12-11T10:27:45.000199 | Heide |
clojurians | clojure | There's still no `(Long/valueOf ...)` that takes an Integer, sadly | 2017-12-11T10:29:52.000344 | Mallie |
clojurians | clojure | <@Mallie> `#(Long/parseLong (str %))` ? | 2017-12-11T10:30:27.000579 | Johana |
clojurians | clojure | That would work, yes. It's just a bit horrible :wink: But it would work... | 2017-12-11T10:31:08.000936 | Mallie |
clojurians | clojure | <@Mallie> or something with `number?` or `string?` would work | 2017-12-11T10:33:58.000533 | Johana |
clojurians | clojure | Indeed | 2017-12-11T10:35:32.000250 | Mallie |
clojurians | clojure | `(cond-> x (string? x) (Long/valueOf))` | 2017-12-11T10:36:14.000086 | Kareen |
clojurians | clojure | Just before I wrote something to wrap `Long.` for string and `long` for number I was wondering if there was something that already did that for me | 2017-12-11T10:36:34.000317 | Mallie |
clojurians | clojure | kinsky or franzy for working with kafka? | 2017-12-11T10:36:38.000437 | Necole |
clojurians | clojure | TBH we just have a very thin shim over the Java native stuff | 2017-12-11T10:36:56.000487 | Mallie |
clojurians | clojure | For Kafka I mean | 2017-12-11T10:37:03.000915 | Mallie |
clojurians | clojure | <@Mallie> That's an approach I often like to take too, with other libs | 2017-12-11T10:38:56.000382 | Necole |
clojurians | clojure | <@Mallie> if you know the keys for which u want this (str or int ->long ) conversion, I think cheshire supports supplying custom decode functions to specify types | 2017-12-11T10:41:21.000701 | Angela |
clojurians | clojure | Will have to see if they think it's interesting enough to let me talk :wink: | 2017-12-11T10:49:54.000515 | Mallie |
clojurians | clojure | What’s it about? I used to work with Kafka, did not yet work with it from clojure yet. | 2017-12-11T10:57:34.000505 | Daine |
clojurians | clojure | We're doing a whole series of inverse ETL pipelines. Instead of extracting data from diverse systems, transforming it, and loading it into a common system we have 1 complex write system and a whole load of read-only clients with different requirements who don't want to have to understand the complexities of it | 2017-12-11T11:41:53.000483 | Mallie |
clojurians | clojure | So we extract from the 1 system, do a whole load of transforms using Kafka topics to connect lots of microservices in a pipeline, then load to somewhere easily client-accessible like S3 | 2017-12-11T11:42:28.000612 | Mallie |
clojurians | clojure | The microservices are commodity a lot of the time, so we have the same code with a slightly different defined config in multiple pipelines | 2017-12-11T11:43:56.000253 | Mallie |
clojurians | clojure | Is that true that using functional programming usually has memory usage overhead?
For example, consider a typical task and typical FP solution for it (it was suggested by consultant).
Task: count all values equal to 10 in an array.
FP solution: `(count (filter #(= % 10) values-array))` which includes creation of intermediate array with all 10's.
What do you think? | 2017-12-11T11:49:56.000890 | Heriberto |
clojurians | clojure | Generally true for operations on sequences creating more sequences, because it all has to be garbage collected, but if that becomes a problem you can either write a more efficient version using reduce, or use transducers, or use transients | 2017-12-11T11:51:45.000790 | Johana |
clojurians | clojure | E.g. using <@Marla>'s xforms lib: `(x/count (filter #(= % 10)) seq)` | 2017-12-11T11:52:47.000232 | Johana |
clojurians | clojure | <@Johana> Thank you! That means that Clojure is in better position here than Java 8+. There's <https://github.com/cognitect-labs/transducers-java> but it's not maintained anymore | 2017-12-11T11:53:51.000112 | Heriberto |
clojurians | clojure | <@Heriberto> I've written versions of that count that use very little memory, and some in other VMs (JS, PyPy) that are allocation free. | 2017-12-11T12:05:45.000393 | Sandy |
clojurians | clojure | Basically instead of counting via a seq you can use reduce and add to the accumulator. So it's something like (reduce inc 0 coll) | 2017-12-11T12:07:18.000459 | Sandy |
clojurians | clojure | (that's psudeo code though ^^) | 2017-12-11T12:07:33.000450 | Sandy |
clojurians | clojure | <@Sandy> Actually I'm asking this to implement handling of map of vectors better. Looks like the best version would be to do reduce-kv which calls reduce in lambda function. | 2017-12-11T12:14:04.000763 | Heriberto |
clojurians | clojure | Yeah, at <@Sandy> says, this is definitely something I’ve explored a bunch. Unfortunately, the various multi-shot tricks are never going to work, but aborting (zero-shot?) is possible via exceptions, and the standard one-shot is pretty easily replicated by simple mutable state. Better yet, 1-shot can be modeled with dynamic variables pretty directly. | 2017-12-11T12:14:40.000527 | Elfreda |
clojurians | clojure | just like you can bind *out*, you can just bind a ^:dynamic function if you want | 2017-12-11T12:15:09.000851 | Elfreda |
clojurians | clojure | and you can play games with bound-fn, with-bindings, and macros and such to create reusable handlers | 2017-12-11T12:15:34.000444 | Elfreda |
clojurians | clojure | <@Heriberto> not sure I understand? How does this change with a map of vectors? | 2017-12-11T12:19:29.000230 | Sandy |
clojurians | clojure | maybe he/she means map on vectors? | 2017-12-11T12:19:47.000672 | Johana |
clojurians | clojure | is there a nice clojure wrapper for the twitter api that’s more up-to-date than <https://github.com/adamwynne/twitter-api> (which is missing `media/upload`)? | 2017-12-11T12:40:57.000724 | Alline |
clojurians | clojure | I stumbled upon the fact that `aset-int`/`aset-long` are ~20x slower than `aset`. I googled around, but the best I could find was
<https://groups.google.com/forum/#!topic/clojure/pZB501dQwjk>
and <http://www.brool.com/post/aset-is-faster-than-aset-int/>
does anyone have a reasonable explanation as to what’s going on? | 2017-12-11T13:17:18.000281 | Xavier |
clojurians | clojure | <@Johana>
```
(ns etl
(:require [clojure.string :as str]))
(def values {1 (re-seq #"\w" "AEIOULNRST")
2 (re-seq #"\w" "DG")
3 (re-seq #"\w" "BCMP")
4 (re-seq #"\w" "FHVWY")
5 (re-seq #"\w" "K")
8 (re-seq #"\w" "JX")
10 (re-seq #"\w" "QZ")})
(defn transform [dataset] (->> dataset
(reduce-kv (fn [result score letters]
(apply assoc result
(flatten (for [letter letters]
[(str/lower-case letter) score])))) {})))
(transform values)
;; output:
{"a" 1 "b" 3 "c" 3 "d" 2 "e" 1
"f" 4 "g" 2 "h" 4 "i" 1 "j" 8
"k" 5 "l" 1 "m" 3 "n" 1 "o" 1
"p" 3 "q" 10 "r" 1 "s" 1 "t" 1
"u" 1 "v" 4 "w" 4 "x" 8 "y" 4
"z" 10}
``` | 2017-12-11T13:18:40.000708 | Heriberto |
clojurians | clojure | that's what I'm talking about | 2017-12-11T13:18:48.000151 | Heriberto |
clojurians | clojure | doing transformation of map {score: [letter1..letterN], score2: [...],...} to map {letter1: score1, ..., letterN: scoreN,...} | 2017-12-11T13:19:55.000082 | Heriberto |
clojurians | clojure | i.e. from map of scores to list of letters to map of letter to score | 2017-12-11T13:20:14.000745 | Heriberto |
clojurians | clojure | <@Sandy>
>not sure I understand? How does this change with a map of vectors?
I mean it would be great to have some super-reduce which could handle nested structures. I still find functions new for me in Clojure. | 2017-12-11T13:28:10.000767 | Heriberto |
clojurians | clojure | there is `tree-seq` and `clojure.walk` | 2017-12-11T13:29:24.000544 | Xavier |
clojurians | clojure | can you give an example of the output? it doesn’t compile | 2017-12-11T13:29:58.000520 | Johana |
clojurians | clojure | Yeah, one thing that should be pointed out, is that seqs do allocation, and create garbage, but they are also *really* fast. Don't worry about using seqs at this point. You'll be surprised how fast something like `for` comprehensions work. | 2017-12-11T13:30:55.000067 | Sandy |
clojurians | clojure | Try <https://github.com/chbrown/twttr> (up to date)
and <https://github.com/yusuke/twitter4j> (a bit outdated) | 2017-12-11T13:32:41.000187 | Heriberto |
clojurians | clojure | <@Xavier> I'll try them.
<@Johana> It compiles, just requires clojure.string
<@Sandy> I'll take your word for it. :slightly_smiling_face: Speed is the main characteristic. And this method isn't processing gigabytes of data to worry about memory too much. | 2017-12-11T13:36:48.000680 | Heriberto |
clojurians | clojure | <@Heriberto> I got that, but I get “Don’t know how to create ISeq from: java.lang.Long”. I’d rather have the expected output than the code. | 2017-12-11T13:37:25.000408 | Johana |
clojurians | clojure | <@Johana> Sorry for that, added `ns`, corrected input values and added output to code above. | 2017-12-11T13:39:26.000446 | Heriberto |
clojurians | clojure | <@Heriberto> What if there are duplicates? 1 -> “abc”, 2 -> “bxz” ? | 2017-12-11T13:41:05.000630 | Johana |
clojurians | clojure | <@Johana> It's assumed that there are no duplicates. | 2017-12-11T13:41:57.000343 | Heriberto |
clojurians | clojure | just in case, `re-seq` here is just a shortcut for list of letters | 2017-12-11T13:42:37.000402 | Heriberto |
clojurians | clojure | no need to use re-seq there, you can handle strings as a seq in most functions | 2017-12-11T13:43:19.000023 | Johana |
clojurians | clojure | Here’s how I would do it:
```
(defn transform [dataset]
(into {}
(mapcat
(fn [[k vs]]
(for [v vs]
[v k]))
values)))
``` | 2017-12-11T13:43:36.000230 | Johana |
clojurians | clojure | <@Johana> Amazing, that's much better! Thank you a lot!
<@Xavier>, <@Sandy> Thank you very much too! | 2017-12-11T13:48:14.000219 | Heriberto |
clojurians | clojure | you can do this with drop-while and iterate ```=> (first (drop-while #(< % 100) (iterate #(* 2 %) 3)))
192``` | 2017-12-11T13:52:25.000509 | Margaret |
clojurians | clojure | I checked twttr, which looks nice; it doesn’t support `media/upload` either, but it might be a nicer place to start for adding support for it. | 2017-12-11T13:57:39.000019 | Alline |
clojurians | clojure | <@Elfreda> <@Sandy>: is there a nice talk of this somewhere? regardless of whether it can be implemented in clojure, I want to understand how it works | 2017-12-11T14:33:56.000724 | Berry |
clojurians | clojure | <@Berry> <https://github.com/papers-we-love/papers-we-love/issues/9> | 2017-12-11T14:50:08.000402 | Elfreda |
clojurians | clojure | 1. `:` does NOT appear to be a valid keyword
2. (keyword "") returns `:`
is this intended ? | 2017-12-11T15:02:35.000464 | Berry |
clojurians | clojure | <@Elfreda>: would you recommend installing <https://github.com/matijapretnar/eff> and playing with it for a weekend ? | 2017-12-11T15:05:12.000528 | Berry |
clojurians | clojure | ¯\_(ツ)_/¯ if you want | 2017-12-11T15:05:36.000400 | Elfreda |
clojurians | clojure | Yes. `clojure.lang.Keyword/intern` does no validation. Not all possible keywords are readable. | 2017-12-11T15:05:38.000520 | Charity |
clojurians | clojure | Eg. `(keyword "foo bar baz qux :/.")` | 2017-12-11T15:05:59.000478 | Charity |
clojurians | clojure | if you already know ml/ocaml, it’s reasonable to play with it, but last i tried it, it was obviously academic demoware | 2017-12-11T15:06:00.000149 | Elfreda |
clojurians | clojure | not for production use, the full question is:
suppose I wanted to spend a weekend learning how Effects work
would the most efficient route be to download eff and work through a few tutorials in it? | 2017-12-11T15:07:14.000656 | Berry |
clojurians | clojure | <@Elfreda>: ^^ // also, is this the same "eff" system that purescrit uses ? | 2017-12-11T15:08:20.000168 | Berry |
clojurians | clojure | i can’t really answer that question, since i already had a grasp on the fundamental topics via the various analogies i describe in my talk - you’ll have to figure out a learning path that works for you | 2017-12-11T15:08:21.000222 | Elfreda |
clojurians | clojure | <@Xavier> regarding <https://clojurians.slack.com/archives/C03S1KBA2/p1513016238000281> `aset-int` (and similarly for the others) expands into something like:
```
(import '(java.lang.reflect Array))
(defn aset-int
([a idx v] (. Array (setInt a idx (int v))) v)
([a ^int idx v & vs] (apply aset-int (aget a idx) v vs)))
```
which uses Array reflection. Apparently, it's a long standing JVM issue to improve performance in this area (<https://bugs.openjdk.java.net/browse/JDK-8051447>). | 2017-12-11T15:08:37.000063 | Eliana |
clojurians | clojure | I’m not super familiar with PureScript, but I believe it is a haskell-like and therefore Eff in Purescript is the “Eff Monad” which is more or less the same concept, yes | 2017-12-11T15:08:57.000204 | Elfreda |
clojurians | clojure | there’s also Oleg Kiselyov’s writings on “Extensible Effects”, “Extensible Interpreters”, “Freer Monads”, etc | 2017-12-11T15:09:37.000277 | Elfreda |
clojurians | clojure | Thanks for the insight!
Would be nice if that was mentioned in the docs.
Is there any usecase for the `aset-*` functions over `aset` as it stands? | 2017-12-11T15:27:59.000397 | Xavier |
clojurians | clojure | <@Xavier> I think it lets you skip coercing the argument you want to set I guess? | 2017-12-11T15:39:04.000519 | Margaret |
clojurians | clojure | I guess similar to what array reflection is used in Java, building arrays at runtime with the type dependent on some params | 2017-12-11T15:46:38.000370 | Eliana |
clojurians | clojure | hello all, I have long waiting process in `(->> ["<http://www.google.com|www.google.com>" "<http://www.microsoft.com|www.microsoft.com>"] (mapv #(future (ping-host %))) (mapv #(deref %)))`. How do I stop it in the middle of running? | 2017-12-11T16:13:04.000218 | Lois |
clojurians | clojure | you could deref with a timeout | 2017-12-11T16:13:34.000481 | Guillermo |
clojurians | clojure | how come? I want to force interrupt any time, not with timeout | 2017-12-11T16:15:18.000713 | Lois |
clojurians | clojure | is there any way? | 2017-12-11T16:15:37.000260 | Lois |
clojurians | clojure | You can `cancel` a future. | 2017-12-11T16:16:11.000172 | Daniell |
clojurians | clojure | but I have to own the `future` references? | 2017-12-11T16:16:45.000306 | Lois |
clojurians | clojure | a general good practice is to always enforce a timeout. it's better if you own the lifecycle of the future but not required | 2017-12-11T16:17:25.000177 | Guillermo |
clojurians | clojure | is there any `cancel` all? | 2017-12-11T16:17:52.000244 | Lois |
clojurians | clojure | future-cancel can be iffy, though it exists | 2017-12-11T16:18:00.000254 | Margaret |
clojurians | clojure | `future-cancel` or call java interop | 2017-12-11T16:18:03.000374 | Guillermo |
clojurians | clojure | only certain methods are cancellable | 2017-12-11T16:18:08.000492 | Margaret |
clojurians | clojure | ^ | 2017-12-11T16:18:13.000505 | Guillermo |
clojurians | clojure | but most code you would want to cancel is eventually hitting a sleep or an IO op, and those are the cancellable things | 2017-12-11T16:18:49.000669 | Margaret |
clojurians | clojure | that reminds me I should figure out if a cancel will lead to a future exiting if it is doing a non-cancellable thing at that moment the cancel happens but then does a cancellable thing | 2017-12-11T16:19:53.000818 | Margaret |
clojurians | clojure | yes, I´m reading a socket | 2017-12-11T16:20:05.000618 | Lois |
clojurians | clojure | bot outside process can say stop to it | 2017-12-11T16:20:29.000109 | Lois |
clojurians | clojure | *but | 2017-12-11T16:20:32.000286 | Lois |
clojurians | clojure | but then you need the logic around when to future-cancel, and that’s where the time out arg to deref is convenient | 2017-12-11T16:20:34.000410 | Margaret |
clojurians | clojure | if you have that logic already, sure, just hold onto the future and then cancel when needed I guess | 2017-12-11T16:20:57.000457 | Margaret |
clojurians | clojure | ok, but how do I have the future references from here? `(->> ["<http://www.google.com|www.google.com>" "<http://www.microsoft.com|www.microsoft.com>"] (mapv #(future (ping-host %))) (mapv #(deref %)))` | 2017-12-11T16:23:32.000193 | Lois |
clojurians | clojure | change map to other looping function? | 2017-12-11T16:23:59.000057 | Lois |
clojurians | clojure | no, the references are what gets passed to deref | 2017-12-11T16:24:07.000266 | Margaret |
clojurians | clojure | maybe you want a loop inside a future, where the future calls ping-host repeatedly | 2017-12-11T16:24:24.000703 | Margaret |
clojurians | clojure | oh, I see | 2017-12-11T16:24:42.000459 | Lois |
clojurians | clojure | what was the deref for, did someone need to consume the return value or wait for the pings? | 2017-12-11T16:24:52.000283 | Margaret |
clojurians | clojure | wait for all the pings | 2017-12-11T16:25:11.000452 | Lois |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.