workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | `case`'s grouping gets me way too often | 2017-11-27T11:09:09.000768 | Kareen |
clojurians | clojure | yeah, I’m sensitized to look for it now :) | 2017-11-27T11:09:40.000164 | Sonny |
clojurians | clojure | try your luck over <#C051WKSP3|onyx> | 2017-11-27T11:26:52.000134 | Lovie |
clojurians | clojure | I've added a patch for CLJ-2275, pretty straightforward apart from quite a tricky line which I commented on | 2017-11-27T11:38:42.000163 | Kareen |
clojurians | clojure | Thank you, i will check it :+1: | 2017-11-27T11:41:25.000680 | Lanie |
clojurians | clojure | This SO question came about because the person was re-implementing `zipmap` and rolling up their function args with `&` instead of just naming them keys and vals. so the first answer says to overcome this by using `apply`, I suggested naming the args. Please vote on your preferred solution: <https://stackoverflow.com/questions/47517056/how-to-re-implement-zipmap-in-clojure/47518278> | 2017-11-27T15:31:46.000087 | Herlinda |
clojurians | clojure | `lein doo` gives me `Exception in thread "main" java.lang.RuntimeException: No such var: string/includes?, compiling:(cljs/util.cljc:157:13)`, followed by a long stacktrace with compiler internals. How do I know which `cljs/util.cljs` it refers to? It’s apparently from some dependency, not from my project. | 2017-11-27T16:28:57.000295 | Maryann |
clojurians | clojure | I have a string of length 29. I want to create 10 strings of length 2, by dropping every 3rd char from the string. | 2017-11-27T16:31:08.000192 | Berry |
clojurians | clojure | Current idea is to convert to a list of chars, and use drop / partition, but I'm wondering if there ar better string functions. | 2017-11-27T16:31:38.000051 | Berry |
clojurians | clojure | partitioner has a `[n step coll]` arity so just `(parititon 2 3 <your-words>)` | 2017-11-27T16:34:29.000119 | Willow |
clojurians | clojure | `(map #(apply str %) (partition-all 2 3 "abcdefghijklmnopqrstuvxyzabc"))` | 2017-11-27T16:37:12.000028 | Willow |
clojurians | clojure | (partition 2 3 ...) is nice | 2017-11-27T16:47:13.000194 | Berry |
clojurians | clojure | Hi Clojurians. I’m trying to build a simple REST api + clojurescript with re-frame and reagent.. and sass.
So I was thinking to use chestnut template for this. Would it be an overkill? | 2017-11-27T18:39:47.000063 | Tameka |
clojurians | clojure | <@Tameka> it’s useful to start from scratch but there’s a lot of instant gratification from using chestnut; either approach is fine | 2017-11-27T18:44:21.000250 | Georgianne |
clojurians | clojure | Does anyone have any experience using grpc/protobufs from Clojure? I want to use Google Cloud APIs and extract data out of them as persistent maps; I could use the Java API but that means writing a bunch of POJO<=>persistent data structure mapping code that I don’t really need. I guess what I’m saying is: is there a <https://github.com/portkey-cloud/aws-clj-sdk> for grpc? | 2017-11-27T18:45:22.000329 | Georgianne |
clojurians | clojure | If I was writing this from scratch I’d assume I’d write a grpc to gloss compiler | 2017-11-27T18:45:38.000214 | Georgianne |
clojurians | clojure | I do want to start from scratch, but I’m scared of stuartsierra.component library :)) I still don’t quite understand why do I have to use it in the applications. And I’m thinking that I’ll be spending a lot of time figuring out where / how / why to use it in my application | 2017-11-27T18:47:18.000076 | Tameka |
clojurians | clojure | whereas chestnut just has it all set up | 2017-11-27T18:47:49.000305 | Tameka |
clojurians | clojure | you can try compojure via the +handler | 2017-11-27T19:11:53.000408 | Lovie |
clojurians | clojure | <@Tameka> you don’t have to use it, but it prevents problems caused by global mutable singletons for application resources | 2017-11-27T19:25:24.000028 | Margaret |
clojurians | clojure | that’s what I don’t really understand. how is a server instance mutable? | 2017-11-27T19:26:50.000271 | Tameka |
clojurians | clojure | <@Tameka> at one moment in time, it’s running and you can use it to listen for connections, at another moment in time it isn’t | 2017-11-27T19:27:21.000009 | Margaret |
clojurians | clojure | at one moment, it uses your handler to serve requests - at another moment it has a different handler, or different middleware | 2017-11-27T19:27:50.000087 | Margaret |
clojurians | clojure | it’s a resource that has state | 2017-11-27T19:27:54.000030 | Margaret |
clojurians | clojure | how do we avoid the situation where your server is still running and you want a different one? | 2017-11-27T19:28:25.000016 | Margaret |
clojurians | clojure | different server? | 2017-11-27T19:28:42.000132 | Tameka |
clojurians | clojure | it owns a resource that comes from the OS, what if you replace the global reference before stopping it? | 2017-11-27T19:28:55.000130 | Margaret |
clojurians | clojure | component helps streamline these things, not just for your server, but for other things that own limited or unique resources, or manage a mutable internal state | 2017-11-27T19:29:28.000061 | Margaret |
clojurians | clojure | including database connections, or user state, or even graphic windows | 2017-11-27T19:30:24.000045 | Margaret |
clojurians | clojure | what if one mutable or resource owning thing needs to access another one? component helps | 2017-11-27T19:30:53.000295 | Margaret |
clojurians | clojure | hmm so it can be used on front end as well? in cljs? | 2017-11-27T19:31:21.000122 | Tameka |
clojurians | clojure | I meant OS windows, but yes, I also use it in cljs | 2017-11-27T19:31:33.000341 | Margaret |
clojurians | clojure | do you use it instead of re-frame? | 2017-11-27T19:31:57.000084 | Tameka |
clojurians | clojure | doesn’t it have just start and stop methods? | 2017-11-27T19:32:14.000275 | Tameka |
clojurians | clojure | <@Tameka> another important usage is with tests - if your code is made to use components you don’t have to go redefining things in other namespaces to run tests - all you need to do is pass in data that is usable in the right way | 2017-11-27T19:32:15.000105 | Margaret |
clojurians | clojure | <@Tameka> I use it to control the websocket connection, and ensure that when things try to send to the server via websocket and the socket is closed, the messages get saved to send later, and that all the messages go through once the handshake is done | 2017-11-27T19:33:04.000050 | Margaret |
clojurians | clojure | <@Tameka> it ensures that the r/atoms that we create to manage state don’t have to be globals, instead they can be passed in from the component that initializes them on startup and owns them | 2017-11-27T19:33:39.000038 | Margaret |
clojurians | clojure | if you have any public repos that show some simple usages, it would be very helpful to see please | 2017-11-27T19:34:47.000020 | Tameka |
clojurians | clojure | similarly the router that acts on address bar changes - it gets passed routing rules via components, so that it doesn’t need to use globals and be tied to implementation details of the rest of hte app | 2017-11-27T19:35:05.000130 | Margaret |
clojurians | clojure | <@Tameka> sadly this is a closed source app - it’s the product we sell | 2017-11-27T19:35:28.000150 | Margaret |
clojurians | clojure | but there are definitely examples of components out there, and they work on the same principles: if something is mutable or owns a limited resource, make sure it has a specific owner, isn’t global, and gets passed as an argument to things that need it | 2017-11-27T19:36:17.000152 | Margaret |
clojurians | clojure | ok no problem :slightly_smiling_face: thanks for explanation. I think I’ll just need to see in action to actually understand what it does. I’m trying to understand it in other languages I know. perhaps it’s very Clojure related | 2017-11-27T19:38:07.000116 | Tameka |
clojurians | clojure | how do the other languages work with limited or mutable resources? | 2017-11-27T19:39:31.000161 | Margaret |
clojurians | clojure | maybe I should build this app from scratch and perhaps I’ll stumble upon the issue where I’ll have that ‘aah I see’ moment and use it | 2017-11-27T19:39:42.000224 | Tameka |
clojurians | clojure | <@Tameka> in my experience making something around a shared mutable global value, then trying to convert to use an explicit argument later, is a huge pain - it requires a lot of work | 2017-11-27T19:40:24.000219 | Margaret |
clojurians | clojure | if you start with explicit arguments, it’s very easy to make it implicit (or even act like it’s global) in specific scopes if you later decide you need that | 2017-11-27T19:40:51.000340 | Margaret |
clojurians | clojure | it’s not a two way thing - one way is easy, the other is hard | 2017-11-27T19:41:00.000074 | Margaret |
clojurians | clojure | you mentioned the Websocket connection, so in simple terms do you mean that a mutable resource would be a global variable in `js` for example, that holds the connection instance? | 2017-11-27T19:41:41.000003 | Tameka |
clojurians | clojure | yes - and attached logic that ensures that if some other part of the app starts to send, and we are not connected, the message is queued for later | 2017-11-27T19:42:10.000242 | Margaret |
clojurians | clojure | and some data unpacking / packing, stuff like that | 2017-11-27T19:42:23.000044 | Margaret |
clojurians | clojure | but when you use component, it’s not global any more | 2017-11-27T19:42:38.000193 | Margaret |
clojurians | clojure | which means if you need to test it, or use things differently later, you can just replace an argument | 2017-11-27T19:42:53.000122 | Margaret |
clojurians | clojure | instead of rewriting code or faking other namespaces or such | 2017-11-27T19:43:01.000247 | Margaret |
clojurians | clojure | the way I’ve seen it written in some examples, it was assigned to something.. like `(def system (create-system))` where `create-system` returned a `component/system-map` or `component/Lifecycle` | 2017-11-27T19:45:56.000105 | Tameka |
clojurians | clojure | that’s convenient during development but isn’t recommended in an actual application | 2017-11-27T19:46:20.000054 | Margaret |
clojurians | clojure | doesn’t that mean that `system` is global here ? | 2017-11-27T19:46:21.000161 | Tameka |
clojurians | clojure | your code should not rely on that global | 2017-11-27T19:46:27.000137 | Margaret |
clojurians | clojure | but it’s very useful to have that global in your repl | 2017-11-27T19:46:35.000059 | Margaret |
clojurians | clojure | ah so in a production - ready application, I would have something like
```(defn -main [& _]
(let [config (config)]
(-> config
app-system
component/start)))``` | 2017-11-27T19:47:09.000262 | Tameka |
clojurians | clojure | in fact, it’s recommended to only create that def in dev mode, and simply anonymously create the system in prod, without leaving any handle to it anywhere | 2017-11-27T19:47:11.000181 | Margaret |
clojurians | clojure | (copied from chestnut) | 2017-11-27T19:47:15.000168 | Tameka |
clojurians | clojure | exactly | 2017-11-27T19:47:19.000166 | Margaret |
clojurians | clojure | so basically it becomes just an argument to an application | 2017-11-27T19:47:31.000073 | Tameka |
clojurians | clojure | component/start automates the start up order of the parts of the app, and makes sure they can see the other parts they need | 2017-11-27T19:47:59.000124 | Margaret |
clojurians | clojure | damn :smile: I get it now | 2017-11-27T19:48:23.000107 | Tameka |
clojurians | clojure | that’s another advantage, instead of having to mentally juggle the order that things start up because of functional deps, it can just do a topo sort of the tree of deps | 2017-11-27T19:48:32.000360 | Margaret |
clojurians | clojure | you should write a blog post on this! | 2017-11-27T19:48:38.000264 | Tameka |
clojurians | clojure | glad I could help! | 2017-11-27T19:48:42.000261 | Margaret |
clojurians | clojure | maybe I will some day, heh | 2017-11-27T19:48:47.000021 | Margaret |
clojurians | clojure | thank you so much | 2017-11-27T19:48:55.000176 | Tameka |
clojurians | clojure | I guess I was complicating things in my mind | 2017-11-27T19:49:17.000100 | Tameka |
clojurians | clojure | if you think about it, it’s providing the same advantages that fp does over imperative code, on an app architecture level | 2017-11-27T19:49:37.000039 | Margaret |
clojurians | clojure | immutable arguments instead of mutable resources (or at least pretend, as much as you can :smile:) | 2017-11-27T19:49:59.000068 | Margaret |
clojurians | clojure | <@Tameka> See if this simple example helps: <https://github.com/seancorfield/clojure-webapp-live-demo/blob/master/src/webapp/core.clj> -- it uses Component to start/stop a Jetty web server. | 2017-11-27T19:50:17.000251 | Daniell |
clojurians | clojure | nice | 2017-11-27T19:53:34.000229 | Tameka |
clojurians | clojure | thank you <@Daniell> | 2017-11-27T19:53:46.000116 | Tameka |
clojurians | clojure | I know about Integer. and Float.
Is there a clojure function of type "string -> number _or_ nil"
which does
if full string parses to a number, return number
else, return nil | 2017-11-27T19:54:39.000127 | Berry |
clojurians | clojure | I always use `#(try (Long/parseLong %) (catch Exception _))` | 2017-11-27T19:55:36.000096 | Margaret |
clojurians | clojure | or Double/parseDouble as needed | 2017-11-27T19:55:45.000222 | Margaret |
clojurians | clojure | I was under the impressions that exceptions are slow and should be avoided for simple tasks, but I hnever benchmaked it tobe sure | 2017-11-27T19:57:37.000343 | Berry |
clojurians | clojure | catching that exception and returning nil is much simpler than a reliable maybe-read-a-number | 2017-11-27T19:58:01.000223 | Margaret |
clojurians | clojure | and honestly since I only do that parsing at system boundaries, it is guaranteed to never be in a hot loop | 2017-11-27T19:58:22.000111 | Margaret |
clojurians | clojure | so I haven’t had to think about its performance | 2017-11-27T19:58:35.000308 | Margaret |
clojurians | clojure | I’ve got this 6 page SPA that I decided to re-build using clj + cljs. At the moment I’m using `Node.js + Elm` on that one and I’m so motivated to do it :smile: I’ve been playing around with clojure for a while now but haven’t built anything significant yet | 2017-11-27T19:58:53.000123 | Tameka |
clojurians | clojure | if you think that your communication with the outside world is in a hot loop you need to optimize - statistically speaking it’s unlikely you shoudl be using clojure | 2017-11-27T19:59:12.000152 | Margaret |
clojurians | clojure | Exceptions are not slow | 2017-11-27T20:51:27.000007 | Sonny |
clojurians | clojure | is there a builtin for 'apply this function to last element of this vector' or is it a matter of peek, pop, and conj | 2017-11-27T22:28:12.000218 | Berry |
clojurians | clojure | is count on a vector guarnttted to be constant time ?
<https://clojuredocs.org/clojure.core/count> says nothing | 2017-11-27T22:28:59.000144 | Berry |
clojurians | clojure | If I'm trying to compute f^n(x), is the best way simply
(first (drop n (iterate f x))) ? | 2017-11-27T22:34:32.000119 | Berry |
clojurians | clojure | <@Berry> Here is the implementation of the method count() for objects of type PersistentVector in the Java source code for Clojure, which is the type that Clojure vectors are: <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentVector.java#L205-L207> | 2017-11-27T22:39:10.000043 | Micha |
clojurians | clojure | That is the method that clojure.core/count calls when you call count on a Clojure vector, because PersistentVector implements the Counted Java interface (through several intermediate subclass/implements relationships that I won't bore you with unless you want to know). | 2017-11-27T22:40:00.000035 | Micha |
clojurians | clojure | the fastest way to do this is going to be peep/pop, then transform, then push | 2017-11-27T22:40:16.000111 | Sonny |
clojurians | clojure | So for probably all versions of Clojure up to 1.9, you are guaranteed it is constant time. Future versions? Only Rich Hickey knows :slightly_smiling_face: | 2017-11-27T22:40:25.000220 | Micha |
clojurians | clojure | but really if you are asking this question, you are probably using the wrong data structure in the first place | 2017-11-27T22:40:45.000215 | Sonny |
clojurians | clojure | you can see this in Clojure by using `counted?` which indicates a coll can be counted in constant time | 2017-11-27T22:41:36.000126 | Sonny |
clojurians | clojure | if you’re doing something stack-like, use a list (and pop/peek/conj) | 2017-11-27T22:43:15.000024 | Sonny |
clojurians | clojure | so I'm building a parser, where the tokens are stored in a vector | 2017-11-27T22:43:22.000123 | Berry |
clojurians | clojure | most of the time, it's just conj to end of vector, but occasionally I have to modify the last conjed token | 2017-11-27T22:43:39.000062 | Berry |
clojurians | clojure | well, I’d recommend: `(defn transform-last [v f] (conj (pop v) (f (peek v))))` | 2017-11-27T22:47:02.000210 | Sonny |
clojurians | clojure | peek is definitely the fastest way to get the last element of a vector | 2017-11-27T22:47:50.000203 | Sonny |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.