workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
oh, I see that now
2017-11-09T17:37:40.000489
Margaret
clojurians
clojure
I was trying to show some other examples that were incremental improvements upon his original
2017-11-09T17:37:50.000173
Jonas
clojurians
clojure
another suggestion: `(assoc 0 second-letter 1 first-letter)` - assoc is vararg
2017-11-09T17:38:26.000245
Margaret
clojurians
clojure
clojure is fun because you can often come up with a really concise readable version
2017-11-09T17:39:16.000114
Jonas
clojurians
clojure
`(let [[first-letter second-letter :as l] (vec w)] ... )` would do what you need I think? (edited to use `vec` instead of `seq` so `l` is a vector)
2017-11-09T17:39:16.000121
Daniell
clojurians
clojure
you don't need seq there
2017-11-09T17:39:29.000400
Margaret
clojurians
clojure
but as he said, he showed that above
2017-11-09T17:39:48.000242
Margaret
clojurians
clojure
Oh, I didn't scroll back to see -- it's a _very_ long thread :wink:
2017-11-09T17:40:17.000143
Daniell
clojurians
clojure
I think the main take aways are 1) name intermediate variables in a way that helps convey what you’re trying to do if possible 2) if possible try to write a solution that matches a declarative description of the problem. I think the other changes are less important.
2017-11-09T17:43:05.000384
Jonas
clojurians
clojure
```(->> ["hello" "world"] (mapv #(let [[first-letter second-letter :as word] (vec %)] (clojure.string/join (assoc word 0 second-letter 1 first-letter)))))```
2017-11-09T17:43:43.000543
Daniell
clojurians
clojure
(TIL recently: `str/join` uses `""` if you omit the separator)
2017-11-09T17:44:04.000216
Daniell
clojurians
clojure
`assoc`ing into a vector kinda bothers me... I think I'd do `(into [second-letter first-letter] (nnext word))` (and then you don't need the call to `vec`).
2017-11-09T17:51:58.000056
Daniell
clojurians
clojure
<@Daniell> first time I see this « let in map destructuring » coding style... pretty cool
2017-11-09T18:21:41.000427
Ernesto
clojurians
clojure
<https://www.reddit.com/r/Clojure/comments/7btc2k/who_owns_the_twitter_accounts_clojure/>
2017-11-09T22:04:22.000159
Aletha
clojurians
clojure
is there an example of clojure.spec-ing either SVG or HTML so if my 'hiccup data' passes the spec, it's valid HTML/SVG ?
2017-11-09T22:39:28.000013
Berry
clojurians
clojure
in standard usage of spec, when ::foo shows up in different maps (of the same namespace), is it expected that the value associated with ::foo will always be of the same 'shape' ?
2017-11-10T02:54:37.000221
Berry
clojurians
clojure
in spec the mapping of a qualified keyword to a spec (shape) is global by design, so yes.
2017-11-10T04:09:22.000311
Karolyn
clojurians
clojure
though you can make the spec match a set of pretty much arbitrary shapes if you’re set on doing that.
2017-11-10T04:10:12.000151
Karolyn
clojurians
clojure
qqq: Well the value of ::foo must match whatever the spec behind ::foo says. You can use `spec/or` or similar for disjunction.
2017-11-10T04:14:31.000136
Basil
clojurians
clojure
qqq: as for a hiccup "spec", I used <http://p.tarn-vedra.de/hiccup-spec.html> in the past. This also has the benefit of conforming to a nice tree that can be converted to html by a simple tree-walk. Note that `:tag` is just `keyword?`, you can extend htis and `:attrs` with better specs describing the set of allowed tags / attributes.
2017-11-10T04:15:52.000360
Basil
clojurians
clojure
Question about type hinting: I have code like: `(def ms-per-second 1000) (def ms-per-minute (* ms-per-second 60))` - I get a boxed math warning w/ that second def unless I use `(def ms-per-minute (* ^long ms-per-second 60))`. I'd like to type hint `ms-per-second` once where it's defined to avoid needing to type hint it everywhere it's used. Is that possible?
2017-11-10T09:28:45.000030
Deana
clojurians
clojure
yes
2017-11-10T09:30:12.000335
Kareen
clojurians
clojure
however if you want to avoid boxing, you should probably use `^:const` too
2017-11-10T09:30:52.000683
Kareen
clojurians
clojure
Could you please show me what that syntax looks like? I haven't been able to get any placement of the ^long hint to work. I get this error: java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$long@5aadb195
2017-11-10T09:31:51.000263
Deana
clojurians
clojure
in pseudo syntax, what's happening is w/o type hint: `Numbers.multiply (Long(60), (Long)ms-per-second.get())`, w/ type hint: `Numbers.multiply((long) 60, ms-per-second.get().longValue())`, w/ const `Numbers.multiply((long) 60, (long) 1000))`
2017-11-10T09:33:35.000378
Kareen
clojurians
clojure
yeah sure
2017-11-10T09:33:37.000135
Kareen
clojurians
clojure
just `(def ^{:const true :tag 'long} ms-per-second 1000)`
2017-11-10T09:33:52.000292
Kareen
clojurians
clojure
or `(def ^:const ^long ms-per-second 1000)`
2017-11-10T09:34:09.000045
Kareen
clojurians
clojure
the long tag is actually useless with const as the compiler will be able to infer it after inlining
2017-11-10T09:34:32.000072
Kareen
clojurians
clojure
Thank you very much
2017-11-10T09:35:02.000054
Deana
clojurians
clojure
<@Mallory> that use case is very easy to handle with specter: `(transform [ALL (srange 0 2)] clojure.string/reverse ["hello" "world"])`
2017-11-10T09:48:12.000195
Owen
clojurians
clojure
a great example of using composition to avoid having to reinvent the wheel (in this case, string reversal)
2017-11-10T09:51:30.000138
Owen
clojurians
clojure
can you type hint the return of a protocol function signature?
2017-11-10T10:14:59.000243
Magdalena
clojurians
clojure
or do you have to do it at the call site?
2017-11-10T10:15:17.000447
Magdalena
clojurians
clojure
sure
2017-11-10T10:21:01.000138
Kareen
clojurians
clojure
`(defprotocol P (f ^MyType [..]))`
2017-11-10T10:21:56.000424
Kareen
clojurians
clojure
don’t know why I didn’t just try it lol
2017-11-10T10:25:29.000602
Magdalena
clojurians
clojure
Is there a proper channel for asking 1.9 questions? <#C1B1BB2Q3|clojure-spec> ?
2017-11-10T10:44:11.000264
Pauletta
clojurians
clojure
is there anything special about `unq in ``` (s/def :unq/person (s/keys :req-un [::first-name ::last-name ::email] :opt-un [::phone])) ``` or is this literally the `:person` keyword in the `unq` namespace ?
2017-11-10T10:48:45.000551
Berry
clojurians
clojure
`:unq` is the namespace part of the `:unq/person` keyword
2017-11-10T10:58:56.000483
Shamika
clojurians
clojure
there’s nothing really _special_ about it, it could be anything
2017-11-10T10:59:26.000565
Shamika
clojurians
clojure
hey all. I need to set an Object’s field but I don’t know it’s name until runtime.
2017-11-10T11:18:22.000021
Timmy
clojurians
clojure
I’d like to do do: `(set! (.-field object) value)` but I have .-field as a String.
2017-11-10T11:19:21.000044
Timmy
clojurians
clojure
Thanks for this, I was actually including monitor.utils and still had problems. It turns out that it was because I was using CIDER’s refresh functionality (C-c C-x in emacs) instead of `clojure.tools.namespace.repl/refresh`! Still unsure as to why, but at least I found a way around it
2017-11-10T11:19:40.000268
Ted
clojurians
clojure
<@Berry> the single `:` syntax doesn’t presuppose any loading, so there’s no guarantee that unq maps to a namespace at all. `::` will implicitly be a real namespace, as it will either be the current namespace or `::alias/foo` where `alias` will have to have been `require` `:as`’d.
2017-11-10T11:32:52.000683
Magdalena
clojurians
clojure
<https://docs.oracle.com/javase/tutorial/reflect/>
2017-11-10T11:59:52.000322
Rebeca
clojurians
clojure
Anyone know of a way to use ring or bidi to create a url with certain query params from a map? Doing string concatenation feels wrong in this case. I'm trying to general an oauth redirect link.
2017-11-10T12:13:47.000351
Earlie
clojurians
clojure
if they're about spec ask there, otherwise here is fine
2017-11-10T12:24:37.000527
Kareen
clojurians
clojure
Thanks <@Rebeca> I was beginning to suspect I’d need to fall back on Java’s reflection.
2017-11-10T12:27:54.000495
Timmy
clojurians
clojure
definitely with bidi you should be using one of its built in functions for doing that
2017-11-10T12:28:09.000089
Rebeca
clojurians
clojure
path-for
2017-11-10T12:28:53.000198
Rebeca
clojurians
clojure
Is there a recommended way to use protobuf with clojure? The first few projects that come up after a google search don't seem to be actively maintained. I'm specifically looking for something that plays nice with repl dev
2017-11-10T12:43:27.000187
Demarcus
clojurians
clojure
<@Magdalena> <@Shamika>: makes sense; thanks!
2017-11-10T14:32:13.000106
Berry
clojurians
clojure
``` (s/def :event/type keyword?) (s/def :event/timestamp int?) (s/def :search/url string?) (s/def :error/message string?) (s/def :error/code int?) (defmulti event-type :event/type) (defmethod event-type :event/search [_] (s/keys :req [:event/type :event/timestamp :search/url])) (defmethod event-type :event/error [_] (s/keys :req [:event/type :event/timestamp :error/message :error/code])) (s/def :event/event (s/multi-spec event-type :event/type)) (s/explain :event/event {:event/type :event/search :event/timestamp 123456789 :search/url "<https://clojure.org>"}) ``` can someone please explain to me why this is failing? I don't understand the error of: `val: {:event/type :event/search, :event/timestamp 123456789, :search/url "<https://clojure.org>"} fails spec: :event/event at: [nil] predicate: event-type, no method`
2017-11-10T14:37:59.000462
Berry
clojurians
clojure
ah, it works now: the above code works fine; problem was, I initially defined the defmulti wrong, and then upon correction, it was not being redefined until I called a remove-ns
2017-11-10T14:42:25.000055
Berry
clojurians
clojure
you should join the <#C1B1BB2Q3|clojure-spec> channel too
2017-11-10T14:57:18.000290
Shamika
clojurians
clojure
So in working on an application which interacts with PSQL, I’ve setup some standard tooling which pulls dates out of the records and transforms them from sql times to jodatimes (because `clj-time` has this functionality). However, in working with 1.9, the `inst?` operator expects a `java.util.date`. I’m curious if there’s been any public conversation around what timestamps clj should be using going forward, especially now considering there’s `java.time` in jdk 8, etc.
2017-11-10T15:01:06.000430
Pauletta
clojurians
clojure
<@Pauletta> `inst?` works just fine for `java.time.Instant`
2017-11-10T15:03:24.000185
Randee
clojurians
clojure
<@Pauletta> I think at this point I would switch to Java Time. I'm one of the maintainers of `clj-time` and we've been wrestling for a long time with the question of whether to migrate/produce a new version of `clj-time` on top of Java Time. The feeling is that we can't realistically do it in a compatible way and therefore we'd need a new artifact name (rather than change the API and/or semantics and violate the spirit of Rich's Spec-ulation talk) -- so it would be a "new" library altogether (similar to `clj-time`). But none of us have the time(!) or inclination for that, so I'm switching to `clojure.java-time` which is based on Java Time and that's what I'm recommending folks use.
2017-11-10T15:15:19.000040
Daniell
clojurians
clojure
I've introduced `clojure.java-time` at work and we're slowly migrating off our current combination of `date-clj` (for `java.util.Date` stuff) and `clj-time` (for Joda Time stuff).
2017-11-10T15:16:24.000038
Daniell
clojurians
clojure
hello world
2017-11-10T15:19:16.000274
Kathe
clojurians
clojure
i'm trying to use `spyscope` from <https://github.com/dgrnbrg/spyscope>. Added the dependency to my `project.clj` but when I try and add `[require [spyscope.core as spy]` in my namespace, repl refuses to start. The error is: ``` Exception in thread "main" clojure.lang.ExceptionInfo: Call to clojure.core/ns did not conform to spec: In: [2] val: ((require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt])) fails spec: :clojure.core.specs.alpha/ns-form at: [:args] predicate: (cat :attr-map (? map?) :clauses :clojure.core.specs.alpha/ns-clauses), Extra input #:clojure.spec.alpha{:problems [{:path [:args], :reason "Extra input", :pred (clojure.spec.alpha/cat :attr-map (clojure.spec.alpha/? clojure.core/map?) :clauses :clojure.core.specs.alpha/ns-clauses), :val ((require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt])), :via [:clojure.core.specs.alpha/ns-form], :in [2]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x3c7c886c "clojure.spec.alpha$regex_spec_impl$reify__2436@3c7c886c"], :value (spyscope.core "This co" (require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt])), :args (spyscope.core "This co" (require [clojure.pprint :as pp] [clojure.string :as str] [clj-time.core :as time] [clj-time.format :as fmt]))}, compiling:(spyscope/core.clj:1:1) ``` any clues? (oh, and I'm using clojure 1.9.0-RC1)
2017-11-10T15:20:55.000095
Kathe
clojurians
clojure
<@Kathe> Which version of spyscope did you use?
2017-11-10T15:32:40.000107
Daniell
clojurians
clojure
0.1.6 is the latest.
2017-11-10T15:33:11.000404
Daniell
clojurians
clojure
Looks like 0.1.6 includes the fix for the issue you saw above -- I see commits fixing the `ns` forms.
2017-11-10T15:33:39.000567
Daniell
clojurians
clojure
Although it looks like you may run into this <https://github.com/dgrnbrg/spyscope/issues/26> until the maintainer releases 0.1.7.
2017-11-10T15:35:39.000189
Daniell
clojurians
clojure
Good point. My above question was from a standpoint of what should I expect to be using in 6 months, etc. Thanks for pointing this out!
2017-11-10T15:38:41.000245
Pauletta
clojurians
clojure
This is great information. Thanks Sean. The debates we’ve had at work have been mostly the same, but having some indication from the maintainer of clj-time itself definitely helps.
2017-11-10T15:39:58.000372
Pauletta
clojurians
clojure
(that starts out as the bug you encountered <@Kathe> but notes there's a 0.1.6 release but that also has a blocking bug and the library needs a 0.1.7 release made, since the fix is already merged)
2017-11-10T15:41:32.000036
Daniell
clojurians
clojure
`clj-time` will continue to be maintained, but it's much less useful now we have Java Time. I've been very happy with `clojure.java-time` so far in production code.
2017-11-10T15:43:09.000264
Daniell
clojurians
clojure
Hi; I’d like to experiment with program obfuscation and one part I’d like to do via term rewriting — does anyone have a favorite term rewriting library? It seems expresso and stratege and termito are the common ones; expresso seems to be focused on symbolic mathematical expressions, but I don’t think that really matters
2017-11-10T18:12:15.000175
Georgianne
clojurians
clojure
<@Daniell> i downgraded clojure to 1.8.0 and spyscope to 0.1.5. all is well with the world (since i'm not really using spec yet). once i'm done debugging i'll remove spyscope and revert to 1.9.0-RC1. thank you so much!
2017-11-10T20:49:31.000016
Kathe
clojurians
clojure
is there any way to add log or println statements _inside_ a threading macro? looks like it tries to pass the result (`nil`) to the next step. I'd like for the log/print statements to just print the message but otherwise be ignored.
2017-11-11T00:21:02.000036
Kathe
clojurians
clojure
`(-&gt; stuff (doto (println)) more-stuff)` <@Kathe>
2017-11-11T00:30:48.000038
Daniell
clojurians
clojure
<@Kathe> taoensso.timbre/spy can do that for you: `(-&gt; stuff spy more-stuff)` if you're already using timbre
2017-11-11T00:32:04.000015
Ava
clojurians
clojure
(but timbre drags in half the world so unless you're already using it, perhaps a sledgehammer to crack a nut?)
2017-11-11T00:32:38.000054
Daniell
clojurians
clojure
_and I say that as someone who uses timbre in production_
2017-11-11T00:32:51.000040
Daniell
clojurians
clojure
yeah, me too. timbre is .... blunt. but I've found it to be slightly more sane the everything else.
2017-11-11T00:33:36.000011
Ava
clojurians
clojure
and if you don't have timbre, `(def spy #(do (prn %) %))` gets you most of the way there
2017-11-11T00:34:36.000001
Ava
clojurians
clojure
<@Ava> The big plus of timbre for me is that with plugins it can hijack *all* logging and filter it through _one_ place. Otherwise, it's really a pain in the butt.
2017-11-11T00:34:48.000002
Daniell
clojurians
clojure
that's exactly my use case. it took me a bit of time to configure correctly, but I can manage all of my logging in the JVM world via timbre and even configure it at runtime easily
2017-11-11T00:35:28.000001
Ava
clojurians
clojure
We were using bare `tools.logging` at first and that was super fragile, with log4j, so we backed off to just `println` for a while, and then switched to timbre, and we're still not happy.
2017-11-11T00:35:41.000065
Daniell
clojurians
clojure
It's like logging is just a horrible problem and timbre is the least bad of many solutions?
2017-11-11T00:36:11.000059
Daniell
clojurians
clojure
<@Daniell>, <@Ava>: thank you for the suggestions. i'll look into timbre (it seems.. a lot)
2017-11-11T00:48:05.000015
Kathe
clojurians
clojure
for now, i tried the `doto`, `prn`, and `spy` suggestions but none seem to work. here's a minimal example: ``` (defn foo0 [x] (-&gt;&gt; x (* 2))) (defn foo1 [x] (-&gt;&gt; x (doto (println)) (* 2))) (defn foo2 [x] (-&gt;&gt; x (spy "doing the thing with the thing") (* 2))) ```
2017-11-11T00:48:46.000011
Kathe
clojurians
clojure
the function call immediately after the log statement fails with either a cast or arity error.
2017-11-11T00:50:19.000032
Kathe
clojurians
clojure
<@Kathe> I wrote tiny library for this <https://github.com/madstap/hugin>
2017-11-11T02:03:36.000025
Giovanna
clojurians
clojure
It's for exploring at the repl and not a logging library though
2017-11-11T02:04:10.000001
Giovanna
clojurians
clojure
``` (require '[hugin.dbg :as dbg]) (defn foo [x] (-&gt;&gt; x (dbg/p&lt; "Doing the thing with the thing") (* 2))) ``` should work.
2017-11-11T02:06:26.000063
Giovanna
clojurians
clojure
Use `-&gt;` not `-&gt;&gt;`
2017-11-11T02:36:47.000014
Daniell
clojurians
clojure
`-&gt;&gt;` inserts the expression at the _end_ of the form. You want the expression inserted as the _first_ argument, not the last.
2017-11-11T02:37:59.000022
Daniell
clojurians
clojure
hmm, dissoc does not work on vectors. what's the simplest way to remove an element from a vector (by index)?
2017-11-11T08:50:39.000102
Chang
clojurians
clojure
<@Chang> this works: <https://stackoverflow.com/a/18319708/4839573>
2017-11-11T09:26:21.000033
Adele
clojurians
clojure
Just for fun: Writing ansible config in CLJ: <https://gist.github.com/rauhs/a72cfbeef4c80f9a58480484c49e7a51>
2017-11-11T09:49:55.000091
Randee
clojurians
clojure
hmmm, i think i broke my repl environment, but i have no idea how to debug it. when refreshing, it throws exceptions on the `(:require ...)` statements of some files that it cannot find certain modules, where they clearly are defined. after some fierce debugging i was able to get things refreshing, but now my webserver's handlers are suddenly undefined (getting "java.lang.IllegalStateException: Attempting to call unbound fn:" errors) i _think_ something is very wrong somewhere, but i'm unable to pinpoint the issue. sounds like some dangling references / things not getting properly refreshed. any suggestions ?
2017-11-11T11:50:05.000074
Catharine
clojurians
clojure
it's worth noting that `lein run` and the uberjar created with `lein uberjar` run fine
2017-11-11T11:51:55.000037
Catharine
clojurians
clojure
so i think there's definitely something wrong with my reloaded flow somewhere
2017-11-11T11:52:07.000021
Catharine
clojurians
clojure
I just put together <https://github.com/gfredericks/dot-slash-2>, to address some problems with <https://github.com/palletops/lein-shorthand>
2017-11-11T12:31:57.000061
Pearlene
clojurians
clojure
How best to loop over some data and assert it's valid? I tried putting asserts in a doseq but getting strange results: when there is an exception, that iteration is not called.
2017-11-11T14:27:42.000084
Necole
clojurians
clojure
<@Necole> can you expand a bit on what you're trying to do? Perhaps share some code?
2017-11-11T14:44:03.000027
Daniell