workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | not all "reflection" is slow, this is not the case. but it's still a bad idea :) | 2017-11-30T11:33:02.000366 | Kareen |
clojurians | clojure | (-> func var meta :name) | 2017-11-30T11:33:13.000115 | Ha |
clojurians | clojure | that's not how `var` works | 2017-11-30T11:33:39.000647 | Kareen |
clojurians | clojure | ```
user> (bench ((fn [f]
(-> f
.getClass
.getName)) clojure.string/replace))
Evaluation count : 10640280 in 60 samples of 177338 calls.
Execution time mean : 5.649725 µs
Execution time std-deviation : 123.414594 ns
Execution time lower quantile : 5.453163 µs ( 2.5%)
Execution time upper quantile : 5.886103 µs (97.5%)
Overhead used : 8.291648 ns
Found 1 outliers in 60 samples (1.6667 %)
low-severe 1 (1.6667 %)
Variance from outliers : 9.4543 % Variance is slightly inflated by outliers
nil
``` | 2017-11-30T11:39:25.000113 | Hedwig |
clojurians | clojure | 5µs, depending on the use case, can be a long time, i agree | 2017-11-30T11:39:57.000392 | Hedwig |
clojurians | clojure | well, there's 2 instances of reflection in this code, one is avoidable and it's the slow reflection, the other is `.getClass` itself which is fast | 2017-11-30T11:42:19.000960 | Kareen |
clojurians | clojure | just rebench with `(fn [^Object f]` and you'll see what I mean | 2017-11-30T11:42:34.000386 | Kareen |
clojurians | clojure | I'll do. | 2017-11-30T11:42:55.000533 | Hedwig |
clojurians | clojure | ```
user> (bench ((fn [^Object f]
(-> f
.getClass
.getName)) clojure.string/replace))
Evaluation count : 5075442000 in 60 samples of 84590700 calls.
Execution time mean : 4.068115 ns
Execution time std-deviation : 0.410098 ns
Execution time lower quantile : 3.483281 ns ( 2.5%)
Execution time upper quantile : 4.942832 ns (97.5%)
Overhead used : 8.291648 ns
Found 2 outliers in 60 samples (3.3333 %)
low-severe 2 (3.3333 %)
Variance from outliers : 70.3505 % Variance is severely inflated by outliers
``` | 2017-11-30T11:45:13.000168 | Hedwig |
clojurians | clojure | right, and that's essentially free | 2017-11-30T11:45:38.000370 | Kareen |
clojurians | clojure | 4ns? What happened? :flushed: | 2017-11-30T11:45:44.000615 | Hedwig |
clojurians | clojure | you got rid of the avoidable reflection :) | 2017-11-30T11:46:00.000891 | Kareen |
clojurians | clojure | I have to read about this reflection thing. Thank you! | 2017-11-30T11:46:14.000109 | Hedwig |
clojurians | clojure | *this* is what in clojure we refer as reflection, but generally speaking my point was that in java lang, Object.getClass is technically reflection too | 2017-11-30T11:46:58.000777 | Kareen |
clojurians | clojure | but when we talk about reflection in clojure, it's in the context of *reflective calls at runtime* which is a very narrow and specific instance of reflection | 2017-11-30T11:47:21.000160 | Kareen |
clojurians | clojure | which is what your function was also doing, but unnecessarily | 2017-11-30T11:47:34.000544 | Kareen |
clojurians | clojure | Do you have an example where you cannot avoid reflection? | 2017-11-30T11:49:13.000027 | Hedwig |
clojurians | clojure | Reflection in the wider sense. | 2017-11-30T11:49:22.000570 | Hedwig |
clojurians | clojure | if you want to do stuff like `(deftype Foo [x]) (deftype Bar [x]) (defn foo [a] (.-x a))` then that needs to be reflective | 2017-11-30T11:50:06.000873 | Kareen |
clojurians | clojure | but generally speaking reflection is avaoidable in 90% of the cases | 2017-11-30T11:50:18.000690 | Kareen |
clojurians | clojure | Thx :simple_smile: | 2017-11-30T11:51:22.000432 | Hedwig |
clojurians | clojure | np | 2017-11-30T11:53:05.000396 | Kareen |
clojurians | clojure | <@Kareen> this means i should typehint my parameteres when possible? only functions? is there a way in which I can `clojure.spec`stuff and get type hints for free? | 2017-11-30T12:27:15.000063 | Amado |
clojurians | clojure | no don't start type hinting everything | 2017-11-30T12:27:39.000284 | Kareen |
clojurians | clojure | my suggestion is to `(set! *warn-on-reflection* true)` in your project at dev time and just type hints the warnings away | 2017-11-30T12:28:09.000108 | Kareen |
clojurians | clojure | there's no way to get type hints from clojure.spec, type hints are compile time and spec is runtime | 2017-11-30T12:28:27.000028 | Kareen |
clojurians | clojure | thanks :slightly_smiling_face: | 2017-11-30T12:33:55.000349 | Amado |
clojurians | clojure | addendum about warn-on-reflection - if you use lein, `lein check` will show all your reflection warnings | 2017-11-30T12:41:07.000714 | Margaret |
clojurians | clojure | maybe cursive may warn me about those with a little config? | 2017-11-30T12:45:56.000160 | Amado |
clojurians | clojure | What do you use for data validation? Clojure spec looks great to generate and check data validation, but on the other hand it is totally not human readable. So using clojure spec i would have to validate twice, once with clojure spec and once for users with usability messages. It sound like something is wrong in this pattern. How do you do this? I would like to use clojure spec but something deep inside me saying i need complete solution to generate, validate, human readable information and spec doesn’t fit into this at that moment. | 2017-11-30T14:23:45.000358 | Gladys |
clojurians | clojure | <@Gladys> there are libraries for mapping from the spec errors to human readable messages, the intention for spec is to be easy to integrate with tooling for readability | 2017-11-30T14:25:27.000516 | Margaret |
clojurians | clojure | <@Gladys> We use just spec -- and then `explain-data` for failures, and we map the data structure to our own custom error messages. | 2017-11-30T14:25:39.000002 | Daniell |
clojurians | clojure | Do you have some public example? | 2017-11-30T14:29:19.000798 | Gladys |
clojurians | clojure | No, sorry. It's code at work. | 2017-11-30T14:46:32.000195 | Daniell |
clojurians | clojure | has anyone written a `let` style macro that puts the bindings at the end? I do like the haskell `where` syntax whereby the local definitions can follow after usage | 2017-11-30T15:02:21.000170 | Willow |
clojurians | clojure | dpsutton, does that have some benefit im not understanding? | 2017-11-30T15:03:51.000064 | Sherrie |
clojurians | clojure | just for clarity of reading. For example you define a function and have a bunch of stuff in the let bindings and there's a lot of details immediately and then the implementation. The `where` style let's you put some clear logic and then define the local bindings after their usage. A macro could simple rewrite this into a traditional let but i do like the usage first | 2017-11-30T15:04:57.000459 | Willow |
clojurians | clojure | I did something like that in my raft implementation | 2017-11-30T15:06:38.000282 | Rebeca |
clojurians | clojure | <https://github.com/hiredman/raft/blob/master/src/com/manigfeald/raft/rules.clj#L131-L145> | 2017-11-30T15:06:40.000505 | Rebeca |
clojurians | clojure | ah thanks! | 2017-11-30T15:06:44.000440 | Willow |
clojurians | clojure | <@Sherrie> and example is the following:
```
levelorder :: (Ord a) => Tree a -> [a]
levelorder t = step [t]
where
step [] = []
step ts = concatMap elements ts ++ step (concatMap subtrees ts)
elements Nil = []
elements (Node left x right) = [x]
subtrees Nil = []
subtrees (Node left x right) = [left,right]
``` | 2017-11-30T15:08:41.000257 | Willow |
clojurians | clojure | with good naming it can make the logic really clear and push the details down below but still close if you are interested | 2017-11-30T15:08:59.000333 | Willow |
clojurians | clojure | it has these things I called "rules" that have three parts, a true/false expression that determines if the body should be applied, a body that updates the passed in state, and then bindings (usually a big destructuring) that establish any bindings for the first two parts | 2017-11-30T15:09:12.000176 | Rebeca |
clojurians | clojure | in clojure, the let puts all of the stuff above. i can see both having their benefits but sometimes just want to see a nice clear logic | 2017-11-30T15:09:25.000334 | Willow |
clojurians | clojure | <@Willow> I think Ive done too much Clojure and too little Haskell to find that order help. Looks upside down to me :slightly_smiling_face: | 2017-11-30T15:09:49.000449 | Sherrie |
clojurians | clojure | that's the point | 2017-11-30T15:09:55.000400 | Willow |
clojurians | clojure | one thing with the let ordering is that it's the same dependency order as defn/def ordering, so there's some consistency here. also with imperative language statement ordering | 2017-11-30T15:10:41.000564 | Aldo |
clojurians | clojure | yeah i'm thinking some syntax like
```
(with-delayed-context
(-> (sanitize-data data)
(filter incomplete?)
(map complete-names))
(with-bindings [sanitize-data (fn [data] ...)
incomplete? (fn [item] (and ...))
complete-names (fn [item] (or ...))]))
``` | 2017-11-30T15:14:26.000135 | Willow |
clojurians | clojure | put the high level logic at the top and the details below | 2017-11-30T15:14:43.000377 | Willow |
clojurians | clojure | but better names than with-delayed-context and with-bindings | 2017-11-30T15:15:02.000495 | Willow |
clojurians | clojure | ```(defn where [body bindings] `(let ~bindings ~body))``` | 2017-11-30T15:17:03.000136 | Rebeca |
clojurians | clojure | but you lose the implicit do i believe. that's why i was thinking a keyword to signal the end of the body | 2017-11-30T15:17:32.000337 | Willow |
clojurians | clojure | so keep taking forms as the body until you see the `with-bindings` or `where` and then invert | 2017-11-30T15:17:52.000712 | Willow |
clojurians | clojure | or just use `do` if you need one | 2017-11-30T15:17:54.000659 | Rebeca |
clojurians | clojure | ```(defmacro where
[& body-and-bindings]
`(let ~(last body-and-bindings)
~@(butlast body-and-bindings)))```
```user=> (where (+ x y) [y 1 x (inc y)])
3``` ? | 2017-11-30T15:48:41.000429 | Margaret |
clojurians | clojure | ah, don't overcomplicate it. nice | 2017-11-30T15:50:43.000739 | Willow |
clojurians | clojure | could anyone shed some light on why this doesn't work?
```
(mapcat :id
[[{:id 1} {:id 2}]
[{:id 3} {:id 4}]])
``` | 2017-11-30T15:53:53.000518 | Dede |
clojurians | clojure | this works fine | 2017-11-30T15:54:32.000012 | Dede |
clojurians | clojure | `(map :id [{:id 1} {:id 2} {:id 3} {:id 4}])` | 2017-11-30T15:54:35.000029 | Dede |
clojurians | clojure | <@Dede> `[{:a 0}]` doesn’t have an :a key | 2017-11-30T15:55:02.000381 | Margaret |
clojurians | clojure | it’s a vector containing an item with an :a key | 2017-11-30T15:55:12.000206 | Margaret |
clojurians | clojure | mapcat unfolds after, not before, the input list | 2017-11-30T15:55:28.000189 | Margaret |
clojurians | clojure | you could do `(map :id (apply concat coll))` instead | 2017-11-30T15:55:39.000595 | Margaret |
clojurians | clojure | or `(into [] (comp cat (map :id)) coll)` | 2017-11-30T15:56:09.000403 | Margaret |
clojurians | clojure | awesome, thanks! | 2017-11-30T15:56:23.000516 | Dede |
clojurians | clojure | does anyone have experience with ssl on heroku? | 2017-11-30T21:24:43.000025 | Jasmin |
clojurians | clojure | i have an api running on immutant | 2017-11-30T21:24:51.000175 | Jasmin |
clojurians | clojure | apparently its stupid easy lol | 2017-11-30T21:29:36.000167 | Jasmin |
clojurians | clojure | ¯\_(ツ)_/¯ | 2017-11-30T21:29:38.000117 | Jasmin |
clojurians | clojure | hello! I'm confused about project dependencies when linking to clojure from another JVM language; I've articled my problem/question fully here: <https://stackoverflow.com/questions/47586889/handling-clojure-project-dependencies-when-dynamically-linking-to-clojure-runtim>. If anyone could help that would be greatly appreciated :smile: | 2017-12-01T00:51:03.000079 | Carlene |
clojurians | clojure | <@Carlene> I have similar setup for two projects. I have Clojure code compiled as überjar, intended to be used as a library from Java (and some Java classes calling the Clojure code - :gen-class won't create javadoc for classes/methods and my colleagues would be upset :slightly_smiling_face: ). I ended up with embedding nREPL in the project. I copied code from this library: <https://github.com/jarohen/embed-nrepl> . From Java code I call the Clojure method to start repl during application start. Then I can connect to that from emacs. | 2017-12-01T01:15:01.000006 | Cristie |
clojurians | clojure | I'll second that. For a long time -- as we introduced Clojure into our stack -- we used the "Java API" to call Clojure from our legacy application and we started a REPL server inside that code which we could connect to from Emacs or the command line and have our regular fast-feedback Clojure workflow. | 2017-12-01T01:20:37.000134 | Daniell |
clojurians | clojure | so to use clojure in a legacy codebase with coworkers who don't want to use java, you are:
1. compiling *.clj iknto uberjar
2. when the uberjar is called from java, firing up a nrepl
3. so now you have a clojure repl into your legacy java app (that still "starts from java") ? | 2017-12-01T01:22:52.000098 | Berry |
clojurians | clojure | One thing I'll observe is that we deliberately did *not* create an uberjar and deploy things that way -- we decided to deploy as source and put the `src` folder on the classpath of the legacy application (along with any Clojure libraries we needed). This meant we could modify source if needed and `require` `:reload` to pick up changes (I'll say that we rarely do this now, but it was common when we first started embedding Clojure). | 2017-12-01T01:23:00.000181 | Daniell |
clojurians | clojure | The progression for us was that we started using Clojure as a small, isolated "library language" for low-level stuff and it gradually expanded until it became our primary language. Now we do all new development in Clojure and our legacy systems are shrinking as we replace functionality with pure Clojure microservices and applications. | 2017-12-01T01:27:13.000063 | Daniell |
clojurians | clojure | What is the best way to type hint an `Object[]` array in Clojure? I've seen this method `#^"[Ljava.lang.Object;"` here (<http://disq.us/p/1buoakl>), but I'm not sure it's officially supported. | 2017-12-01T05:50:51.000463 | Danyel |
clojurians | clojure | <@Danyel> Check out `to-array` source. | 2017-12-01T05:56:11.000095 | Randee |
clojurians | clojure | <@Randee> thanks | 2017-12-01T06:03:09.000243 | Danyel |
clojurians | clojure | <@Danyel> ^objects works as well | 2017-12-01T07:55:41.000036 | Rosia |
clojurians | clojure | <@Jacelyn> thx! weird that it's not in the official docs | 2017-12-01T07:56:19.000209 | Danyel |
clojurians | clojure | That will not work on vars by the way, only in signatures | 2017-12-01T08:20:40.000201 | Sonny |
clojurians | clojure | It’s supported | 2017-12-01T08:21:10.000350 | Sonny |
clojurians | clojure | What’s the rationale behind `nthrest`? Noticed it for the first time today. What about `(drop n ...)` wrapped in `doall` if you need it strict? | 2017-12-01T09:58:40.000695 | Johana |
clojurians | clojure | It seems to be born out of a refactor of `partition`:
<https://github.com/clojure/clojure/blame/b98ba848d04867c5542d50e46429d9c1f2472719/src/clj/clojure/core.clj#L3166>
(cc <@Dirk>) | 2017-12-01T10:06:30.000087 | Johana |
clojurians | clojure | Interestingly, they both seem to have a `recur` pattern that is eagerly done to consume the beginning of the sequence. | 2017-12-01T10:08:19.000045 | Dirk |
clojurians | clojure | so the difference is `nthrest` skips `n` immediately and `drop` only when the sequence is consumed | 2017-12-01T10:10:54.000476 | Johana |
clojurians | clojure | `nthrest` is eager initially, while `drop` staves off the initial eagerness | 2017-12-01T10:10:59.000194 | Dirk |
clojurians | clojure | hmm yeah, so `(doall (drop ...))` would consume everything in the dots too, while `nthrest` leaves that to the consumer of the seq | 2017-12-01T10:12:56.000462 | Johana |
clojurians | clojure | You do have an interesting question regarding rationale, especially given that `nthrest` wasn't added until 1.3 | 2017-12-01T10:13:59.000307 | Dirk |
clojurians | clojure | maybe `(drop ...)` caused an issue in the impl of partition? | 2017-12-01T10:15:31.000515 | Johana |
clojurians | clojure | I guess not, because that *was* the impl before: <https://github.com/clojure/clojure/commit/82c72549f455e68a314593c67436e7a14c64a931> | 2017-12-01T10:16:26.000533 | Johana |
clojurians | clojure | <@Johana> If you are curious as to my rationale for using `nthrest`: It was simply that I had used `rest` (instead of `(drop 1 ...)`, so when I needed to revise the code to drop more items, I reached for `nthrest` without thinking about it too deeply. I certainly wasn't thinking about laziness, whether to employ transducers, or any such deeper analysis. | 2017-12-01T10:27:40.000204 | Dirk |
clojurians | clojure | Yeah, when I saw your code I started thinking about transducers. It lends itself well for it. But whatever, that’s not better or worse, just different and maybe overthinking a puzzle :slightly_smiling_face: | 2017-12-01T10:28:35.000079 | Johana |
clojurians | clojure | FWIW, I think your final solution using `drop` is the cleanest, easiest to read, especially given that the revised code needed to drop more than 1 item. | 2017-12-01T10:31:25.000073 | Dirk |
clojurians | clojure | How would I write this more concisely? `(let [d {:a [{:b 1 :deleteme "foo"}]} f #(dissoc % :deleteme)] (update-in d [:a] #(mapv f %)))` | 2017-12-01T10:35:29.000405 | Altagracia |
clojurians | clojure | There is also an argument that some functions are a bit esoteric (and perhaps should be avoided). `drop` is used 50 times more frequently than `nthrest`in the data in <http://www.lispcast.com/100-most-used-clojure-expressions>
My favorite example Var in that category is `when-first`. It is hard to justify using `when-first` given that it never became part of the "idiom". | 2017-12-01T10:38:17.000702 | Dirk |
clojurians | clojure | Never heard about it | 2017-12-01T10:38:43.000068 | Johana |
clojurians | clojure | nthrest is also not used in the rest of the clojure codebase | 2017-12-01T10:39:56.000417 | Johana |
clojurians | clojure | Indeed, that's the problem with using Vars like that. It is like using a "dictionary word" in conversation, where the other participants in the conversation get stuck on what you just said. | 2017-12-01T10:40:04.000820 | Dirk |
clojurians | clojure | `update` is now in core for updating when the path `[:a]` only has one segment. | 2017-12-01T10:40:14.000466 | Guillermo |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.