workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
the closest thing would be `(map #(%1 %2) ...)`
2017-12-10T14:44:11.000134
Margaret
clojurians
clojure
``` (def a-z (mapv int->char (range (char->int \a) (inc (char->int \z))))) (def letters-lower "abcdefghijklmnopqrstuvwxyz") ``` besides listing out the answer, is there a way to make the def of a-z shorter ?
2017-12-10T15:19:49.000082
Berry
clojurians
clojure
Is there something like `(binding [*ns* 'afsdfsd] ::a)` but that works? ('work' -> result in `:afsdfsd/a`)
2017-12-10T16:35:12.000037
Kristy
clojurians
clojure
no
2017-12-10T16:35:32.000106
Kareen
clojurians
clojure
read time happens too early for that to work
2017-12-10T16:35:49.000051
Kareen
clojurians
clojure
yeah, guessed so... thanks for the confirmation! useful coming from tools.analyzer author :slightly_smiling_face:
2017-12-10T16:36:37.000045
Kristy
clojurians
clojure
np
2017-12-10T16:36:58.000006
Kareen
clojurians
clojure
hey everyone, how can I lowercase the keys in map? :smile: I have the following: ``` {:CurrentGame 1 :Score 30}``` and I want to lowercase the keywords
2017-12-10T17:36:56.000004
Tameka
clojurians
clojure
this response comes from the server as json and when it is converted from json using clj-http, that’s how it shows up
2017-12-10T17:37:46.000004
Tameka
clojurians
clojure
solved it like this ``` (defn lower-case-keys [result] (if (map? result) (into {} (for [[k v] result] [(keyword (lower-case (name k))) v])) (map lower-case-keys result))) ```
2017-12-10T17:46:13.000140
Tameka
clojurians
clojure
(reduce-kv #(assoc %1 (keyword (lower-case ( name %2))) %3) {} json-response) something this
2017-12-10T17:46:35.000008
Daine
clojurians
clojure
I like that one too!
2017-12-10T17:47:01.000020
Tameka
clojurians
clojure
I just needed my fn to support vectors / lists too
2017-12-10T17:47:22.000090
Tameka
clojurians
clojure
didn’t know about reduce-kv, thanks!
2017-12-10T17:47:29.000081
Tameka
clojurians
clojure
personally I like to use my own syntax sugar
2017-12-10T18:01:10.000106
Leann
clojurians
clojure
``` (defn map-keys [f m] (->> m (map (fn [[k v]] [(f k) v])) (into {}))) (defn map-vals [f m] (->> m (map (fn [[k v]] [k (f v)])) (into {}))) ```
2017-12-10T18:01:13.000038
Leann
clojurians
clojure
<@Tameka> with specter: `(transform [MAP-KEYS NAME] clojure.string/lower-case m)`
2017-12-10T18:34:55.000080
Owen
clojurians
clojure
also does not change the type of the map and much higher performance than other approaches, especially for small maps
2017-12-10T18:36:10.000041
Owen
clojurians
clojure
you can also do it with transducers and avoid creating the intermediate seq like this <@Tameka> ```(defn lower-case-keys [m] (into {} (map (fn [[k v]] [(-&gt; k name lower-case keyword) v])) m))```
2017-12-10T18:59:55.000162
Toi
clojurians
clojure
I'm sure I've asked this before. Is <https://clojuredocs.org/clojure.core/count> constant time? if not, what is ?
2017-12-11T00:17:23.000127
Berry
clojurians
clojure
count is constant time if the object you call it on is counted?
2017-12-11T00:17:54.000005
Margaret
clojurians
clojure
I'm counting a vector.
2017-12-11T00:18:07.000035
Berry
clojurians
clojure
yes that's constant time
2017-12-11T00:18:20.000009
Margaret
clojurians
clojure
```+user=&gt; (counted? []) true ```
2017-12-11T00:18:38.000093
Margaret
clojurians
clojure
to be pedantic, that proves that the empty vec is counted, it says nothing about vecs in general :slightly_smiling_face:
2017-12-11T00:21:46.000039
Berry
clojurians
clojure
there are no collections that special case- counted? is checking for implementation of an interface
2017-12-11T00:23:09.000056
Margaret
clojurians
clojure
does clojure have an insert-at-index ?
2017-12-11T01:07:57.000017
Berry
clojurians
clojure
I want '(1 2 3) ':a -&gt; '(1 :a 2 3)
2017-12-11T01:08:07.000163
Berry
clojurians
clojure
where I want to insert into thedlist at the ith-index
2017-12-11T01:08:15.000034
Berry
clojurians
clojure
there's a finger tree library that works that way
2017-12-11T01:11:12.000155
Margaret
clojurians
clojure
yeah, I guess with either vector or list, insertion at arbitrary index can be expensive
2017-12-11T01:21:37.000061
Berry
clojurians
clojure
Hmm, I kinda wonder what is the reasoning to add the CLI tools into Clojure 1.9? I kinda get the “clj” command to easily launch a Clojure REPL without first having to create a leiningen/boot project but rest of the stuff is kinda not-so-necessary to me?
2017-12-11T02:22:13.000106
Cecilia
clojurians
clojure
Not saying it isn’t ok that it is there now but I would have prioritised things differently for 1.9 release :sheep:
2017-12-11T02:22:56.000111
Cecilia
clojurians
clojure
it’s like a poor man’s Leiningen or Boot
2017-12-11T02:24:20.000002
Cecilia
clojurians
clojure
maybe it’s there to lower the barrier of entry for newbies?
2017-12-11T02:25:39.000024
Cecilia
clojurians
clojure
is there a more idiomatic way to write: `(vec(apply concat (for ...)))`
2017-12-11T03:33:25.000217
Berry
clojurians
clojure
`(vec (apply concat (for ...)))`
2017-12-11T03:33:35.000189
Berry
clojurians
clojure
<@Cecilia> I think it makes sense if you consider other ecosystems. We need at least 3 tools to work with a language: an interpreter/compiler, a dependency manager and a build tool
2017-12-11T03:39:38.000154
Jami
clojurians
clojure
before, we had boot and lein to implement all these tools. But now, we can have a clean separation with CLI tools providing the interpreter and dependency manager, and lein/boot providing the build tool
2017-12-11T03:41:54.000375
Jami
clojurians
clojure
I also like that tools.deps.alpha attempts to standardize the dependencies in Clojure project
2017-12-11T03:42:39.000243
Jami
clojurians
clojure
and I remember how confuse I was when I tried to learn Clojure. I didn't understand why there was no "clojure interpreter", and we had to rely on leiningen
2017-12-11T03:43:41.000382
Jami
clojurians
clojure
it would be like for C++, we had to install cmake to use the language
2017-12-11T03:44:17.000260
Jami
clojurians
clojure
<@Berry> you could use `mapcat` instead of the for loop `(vec (mapcat f coll))`
2017-12-11T03:47:11.000473
Jami
clojurians
clojure
was just about to say the same thing to qqq :slightly_smiling_face:
2017-12-11T04:06:48.000053
Cecilia
clojurians
clojure
is there an idiomatic way of replacing every `:f` in `[\a \b :f \c \d :f \e \f :f]` with `[1 2 3]` to give `[\a \b 1 \c \d 2 \e \f 3]`, i.e. find occurence of a specific element (keyword) in a vector an replace with element at index in another vector. I have a somewhat convoluted reduce for this right now but I get the feeling there might be something better
2017-12-11T04:07:40.000108
Joette
clojurians
clojure
I couldn't see how to insert at index with finger tree. Am I missing something obvious?
2017-12-11T04:15:50.000126
Jodie
clojurians
clojure
Oh, derp, I just noticed the `assoc`
2017-12-11T04:17:27.000188
Jodie
clojurians
clojure
Don’t really see anything else then reduce being simpler, you can start the reduce on [0[]] and either conj the value to the second part, or add and to the first value and add both the new first value and conj it?
2017-12-11T04:18:22.000418
Daine
clojurians
clojure
<@Cecilia> have you seen <https://www.youtube.com/watch?v=sStlTye-Kjk> already? This might give some additional insights about the introduced CLI tooling.
2017-12-11T04:26:04.000321
Evelyne
clojurians
clojure
<@Daine> more or less what I'm doing. Thanks for the sanity check.
2017-12-11T04:26:28.000024
Joette
clojurians
clojure
<@Evelyne> nope, will check
2017-12-11T04:27:23.000044
Cecilia
clojurians
clojure
and then there is also the documentation, e.g. <https://clojure.org/reference/deps_and_cli>
2017-12-11T04:27:47.000015
Evelyne
clojurians
clojure
here would be an entry point into the talk specifically for clj: <https://youtu.be/sStlTye-Kjk?t=18m19s> but for context it might be best to watch from the beginning
2017-12-11T04:33:57.000022
Evelyne
clojurians
clojure
<@Evelyne> the core thing I got out of that thing is that Clojure 1.9 is actually 3 jars these days, so based on that it does make sense to build dependency management into Clojure itself to avoid the hassle that would create for users
2017-12-11T04:43:27.000298
Cecilia
clojurians
clojure
<@Cecilia> yeah and as <@Sonny> also said in the talk it (for now) serves as a hassle-free entry point for newcomers as well as a quick way to “just start a REPL”. But I think it fits into the larger picture about dependency management quite well, untangling that from other tasks that for example boot and lein take care of and also I suspect that this might be a step towards solving issues that were outlined in <https://www.youtube.com/watch?v=oyLBGkS5ICk> Maybe <@Sonny> wants to elaborate a bit on the future of `clj`? :slightly_smiling_face:
2017-12-11T04:54:27.000042
Evelyne
clojurians
clojure
aaaaand I am already using it for real to programmatically get a Clojure environment to eval code in :slightly_smiling_face:
2017-12-11T04:55:43.000093
Evelyne
clojurians
clojure
<@Evelyne> What could be easier than this? ``` brew install leiningen lein repl ``` When I started learning Clojure I was surprised to discover how easy it is to get working REPL and to install clojure-mode and inf-clojure (that's what Rich Hickey uses).
2017-12-11T05:10:21.000464
Heriberto
clojurians
clojure
<http://www.eff-lang.org/handlers-tutorial.pdf> &lt;-- has anything like this been implemented in clojure ?
2017-12-11T05:22:29.000141
Berry
clojurians
clojure
why do we have `empty?` and `not-empty` but no `not-empty?`
2017-12-11T05:45:40.000253
Berry
clojurians
clojure
Hi, does anyone have a good idea how to turn a stream of events into a lazy sequence of tails? e.g. `(tails odd? [1 2 3 4 5]) ; =&gt; ((1 2 3 4 5) (3 4 5) (5))`
2017-12-11T05:47:55.000160
Lavera
clojurians
clojure
<@Berry> `not-empty?` is `seq` iirc.
2017-12-11T05:48:13.000477
Jodie
clojurians
clojure
``` (defn lwhile [cur test update] (loop [cur cur] (if (test cur) (update cur) cur))) ```
2017-12-11T05:59:25.000023
Berry
clojurians
clojure
is there a builtin for the lwhile defined above ?
2017-12-11T05:59:30.000130
Berry
clojurians
clojure
Maybe something like this? ``` (defn partition-tails [pred col] (let [[matching &amp; rst :as tail] (drop-while (complement pred) col)] (if matching (lazy-seq (cons tail (tails rst))) ()))) ```
2017-12-11T05:59:48.000532
Lavera
clojurians
clojure
Don't you need a recur in there somewhere? :thinking_face:
2017-12-11T06:00:48.000453
Lavera
clojurians
clojure
And if it is where I suspect, then I don't think there is a builtin... It's something I have been missing quite a few times as well
2017-12-11T06:01:50.000407
Lavera
clojurians
clojure
Don't have much experience with explicit lazy sequences...
2017-12-11T06:02:46.000329
Lavera
clojurians
clojure
granted, somewhat unorthodox use of core async...
2017-12-11T06:05:46.000171
Joette
clojurians
clojure
oh and my solution with partition-by and interleave above was crap
2017-12-11T06:06:41.000016
Joette
clojurians
clojure
```(def test-vec [\a \b \c :f \d:f \e \f :f]) (second (reduce #(if (= :f %2)(let [n (+ 1 (first %1))][n (conj (second %1) n)])[(first %1)(conj (second %1) %2)]) [0 []] test-vec)) [\a \b \c 1 \d 2 \e \f 3]```
2017-12-11T06:19:34.000230
Daine
clojurians
clojure
sorry, it's `(recur (update cur))`
2017-12-11T06:28:33.000266
Berry
clojurians
clojure
<@Daine> doesn't that just increment the 1, 2, 3? the thought was that those values would come from a second vector and could be anything, i.e. the second vector could be `[:x :y :z]` and give `[\a \b \c :x \d :y \e \f :z]`?
2017-12-11T06:29:29.000070
Joette
clojurians
clojure
yes, sou your looking for something else
2017-12-11T06:30:43.000249
Daine
clojurians
clojure
guess I'm starting to like channels for this, feel free to rid me of my infatuation with my newfound use of channels if this is for some reason a bad idea
2017-12-11T06:35:26.000013
Joette
clojurians
clojure
guess the general question would be if it is bad style to pull in core.async just to manage state even in the absence of any concurrency aspects
2017-12-11T06:38:03.000262
Joette
clojurians
clojure
<@Joette> You never do anything in your first benchmark. `map` is lazy.
2017-12-11T06:39:36.000019
Randee
clojurians
clojure
<@Randee> - doh, thank you. Not sure how many times I've done this now
2017-12-11T06:42:33.000347
Joette
clojurians
clojure
Also: You have to recreate your channel among interations. The second loop you'll just insert nil all the time.
2017-12-11T06:42:48.000257
Randee
clojurians
clojure
If you want something stateful and avoid core.async hack you can just create a function like that: ``` (defn make-iter [x] (let [idx (atom -1)] (fn [] (nth x (swap! idx inc))))) ```
2017-12-11T06:43:52.000165
Randee
clojurians
clojure
```(second (reduce #(if (= :f %2)[(rest (first %1)) (conj (second %1) (first (first %1)))][(first %1)(conj (second %1) %2)]) [[1 2 3] []] test-vec))```
2017-12-11T06:44:57.000129
Daine
clojurians
clojure
Ok, Monday, making too many mistakes, signing off
2017-12-11T07:05:53.000072
Joette
clojurians
clojure
Does it make sense for clojure to support this kind of type hinting? ``` (defn f [^longs [x y z]] (+ x y z)) ```
2017-12-11T10:02:05.000015
Johana
clojurians
clojure
so for individual elements it will be inferred that they are longs?
2017-12-11T10:02:21.000315
Johana
clojurians
clojure
<@Elfreda> has been working on a lot of that sort of stuff for some time. IIRC he got some of it working with stock clojure
2017-12-11T10:08:23.000325
Sandy
clojurians
clojure
no
2017-12-11T10:08:29.000117
Kareen
clojurians
clojure
^longs means long array
2017-12-11T10:08:36.000382
Kareen
clojurians
clojure
But sadly, to implement multi-shot handlers in Clojure you'd need some sort of delimited continuation support. The JVM makes that close to impossible (as does almost every other VM on the planet)
2017-12-11T10:09:07.000291
Sandy
clojurians
clojure
you can do that with reduce I think
2017-12-11T10:10:11.000030
Sandy
clojurians
clojure
<@Kareen> &gt; What about when you have a sequence of values, all of a uniform type? Clojure provides a number of special hints for these cases, namely ^ints, ^floats, ^longs, and ^doubles. <https://github.com/clojure-cookbook/clojure-cookbook/blob/master/08_deployment-and-distribution/8-05_type-hinting.asciidoc>
2017-12-11T10:10:17.000810
Johana
clojurians
clojure
but a loop may be easier.
2017-12-11T10:10:35.000339
Sandy
clojurians
clojure
also `(apply + ^longs (list 1 2 3))` works, maybe just by luck
2017-12-11T10:10:54.000074
Johana
clojurians
clojure
And actually I don't think you need the loop in there ethier
2017-12-11T10:11:03.000450
Sandy
clojurians
clojure
``` (defn fix-point [cur test update] (if (test cur) (recur (uprate cur) test update) cur)) ```
2017-12-11T10:11:45.000561
Sandy
clojurians
clojure
That lets you do this without reflection for the `Math/abs` call FWIW: ``` (defn f [^longs arr] (Math/abs (aget arr 0))) (f (into-array Long/TYPE [-1])) ```
2017-12-11T10:12:37.000120
Dirk
clojurians
clojure
<@Johana> the line after the one you posted: &gt;Hinting these types will allow you to pass whole *arrays* as arguments to Java functions and not provoke reflection for sequences
2017-12-11T10:15:37.000127
Kareen
clojurians
clojure
the fact that your apply expression works is because the type hint is just never used there
2017-12-11T10:15:55.000707
Kareen
clojurians
clojure
no, don't use type hints on vectors
2017-12-11T10:16:25.000510
Kareen
clojurians
clojure
it just doesn't do anything
2017-12-11T10:16:28.000229
Kareen
clojurians
clojure
at best
2017-12-11T10:16:34.000356
Kareen
clojurians
clojure
good point, thanks — text is a bit ambiguous about it
2017-12-11T10:16:36.000417
Johana