This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-29
Channels
- # aatree (1)
- # admin-announcements (7)
- # announcements (3)
- # beginners (125)
- # boot (164)
- # braid-chat (8)
- # cider (26)
- # cljsrn (37)
- # clojars (3)
- # clojure (162)
- # clojure-argentina (1)
- # clojure-art (2)
- # clojure-berlin (5)
- # clojure-czech (3)
- # clojure-ireland (1)
- # clojure-miami (1)
- # clojure-norway (9)
- # clojure-russia (47)
- # clojurebridge (1)
- # clojurescript (151)
- # community-development (1)
- # conf-proposals (80)
- # core-async (15)
- # core-matrix (1)
- # cursive (66)
- # datomic (26)
- # emacs (17)
- # events (10)
- # funcool (59)
- # hoplon (43)
- # incanter (2)
- # jobs (10)
- # ldnclj (8)
- # lein-figwheel (18)
- # luminus (1)
- # off-topic (19)
- # om (144)
- # onyx (167)
- # overtone (9)
- # parinfer (12)
- # pedestal (1)
- # proton (158)
- # re-frame (139)
- # reagent (48)
- # test-check (19)
- # testing (43)
Is there a way to globally expose a macro or function in lein?
so I won't have to require it everywhere?
@tom create-window
takes process as the first parameter, so you should be able to do either: create multiple windows in the same process, or create a new window with a different process.
(let [another-process (create-process)]
(w/create-window another-process ...))
But honestly, I don’t know what to do with clj-thrust since the Thrust maintainer seems to have given up on it
if I want to change a handler in a running jetty server from the repl how do I approach that? When I try to store the server in a var (def running (run-jetty ..))
it's unbound. So I have to restart the whole jvm/repl session just to try out a new function, that seems very unclojurish to me so there must be a better way. I have used a little mount in clojurescript but not sure how to approach this.
hey @bbss have you seen Stuart Sierra's Reloaded workflow http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded, his component library: https://github.com/stuartsierra/component and Daniel Szmulewicz' System library: https://github.com/danielsz/system ?
There are components for jetty that handle stop + start within the repl. You can do the same with Mount in Clojure; from a learning perspective though there's probably more documentation available for Component
Yeah I had seen component and read good discussions between proponents of both. But I was afraid that yeah, component has a lot more examples online.
sure- the basic idea for jetty can just be gleaned from the source: https://github.com/danielsz/system/blob/master/src/system/components/jetty.clj
You don’t need the component dependency graph to get started; you just need a lifecycle for your server.
But you’ll be happier if your system state is managed coherently, probably
yeah, it's easy to get started just with tools.namespace and the refresh function, and manual lifecycle at the repl, then decide what pattern to adopt to manage state
@donaldball I understand that, but just getting started understanding clojure workflow so that is a bit much to take on now. In ClojureScript figwheel is quite easy, auto reload.
@jonahbenton: I'll have a look at that too. Thanks.
If you’re just looking for handlers that reload when you change their source, there’s a ring middleware that allows that
sure- yeah, the main difference working on the server compared the client is that instead of just consuming services, you're usually (also) providing them, so you wind up needing some kind of lifecycle management
hmm but sufficiently complex front-end apps communicate back as well right? It just seems front-end can more easily say well lets just reload everything, because there are not many people depending on services so it's less important to be careful what to bring down.
yes, front end can just reload everything because generally it doesn't directly manage anything that corresponds to some machine level resource, like a listening socket, or a database connection- though if you were using local storage or some other physical resource on the front end, similar issues would apply. you would need to be careful about the order in which things were done and unwound
I am confused by two things in this example: https://github.com/danielsz/system/blob/master/src/system/components/jetty.clj 1. How come in this case server (run-jetty ..) does seem to bound? It imports from the same namespace. 2. where does map->WebServer come from. Is it some kind of constructor syntax sugar?
1. see in line 4 the :refer [run-jetty]? https://github.com/danielsz/system/blob/master/src/system/components/jetty.clj#L4 that brings that symbol into the namespace
2. yes, exactly, defrecord is a macro that creates a number of constructor functions
when you use require in the repl (or in a source file), you have a few choices for bringing in symbols from the require'd namespace. if you use the :as form, you introduce a- usually short- symbol that, when suffixed with /, lets you use any symbol in the require'd namespace
if you use the :refer form, then you can bring in specific symbols from the required namespace without any prefix
IOW, (require '[clojure.string :as s]) means you can say s/join or s/lower-case
or you can do (require '[clojure.string :refer [join lower-case]) to bring those symbols in directly, as though you defined them yourself
right, I think I got that, but in my repl when I evaluate my namespace and run jetty-server it seems not to bind to the def var
what error message are you getting?
I am not getting an error message, it starts the server (which might explain it does not return)
ah, so that's the :join? option
you want to (assoc options :join? false)
(.join server) waits for the server to be stopped
the use case is- the .start server step is the last thing you're doing at application startup initialization time/e.g. in -main. unless you have something to keep your application main thread busy, it will exit and your service will stop. (.join server) is a cost-free way of running an infinite loop to keep your server alive
sure thing, good luck!
@tom Thanks. I should at least finalize a 0.1.0 and release that in case anybody is currently using it. I'll have to revisit Electron and see what's possible there. I mean, Electron is fine if you're starting new applications from scratch with ClojureScript, but I created clj-thrust specifically for running already existing Clojure web apps on the desktop. It's unfortunate that Thrust is no longer maintained, because I really like the language-agnostic approach they went with.
It might be possible to achieve something similar with Electron by adding an RPC layer over it, but that's going to be more work on my side. I’ll look into it though.
so the relevant part is:
(start [component]
(let [ws-url (slack/get-ws-url)
conn (slack/rtm-connect ws-url)]
(log/info ws-url)
(assoc component
:url ws-url)
(log/info component)
-------elided---------
log/info
tells me ws-url exists, but even after the assoc, I see that :url
is not changed in component
16-01-29 07:55:57 jethroksy INFO [tob.components] -
16-01-29 07:55:57 jethroksy INFO [tob.components] - #tob.components.WSClient{:id 21, :msg nil, :status nil, :url nil, :conn nil}
@jethroksy: is the component returned from the start
fn?
You need to return component from start (and potentially stop too)
@jethrosky, IINM, assoc doesn't change component. It returns a new map with the :url kry attached.
Yep. And start is just a fn like any other so it needs to return the resultant 'new' component.
which would be nil
been there!
I like the GUI Observer they have in Elixir/Erlang land. Is there a JVM equivalent or something similar?
@bbss: fyi, I handle jetty like this: https://github.com/borkdude/full-stack-clojure-han-okt-2015/blob/master/code/animals-crud/src/animals/repl.clj
Is there a more idiomatic way of applying a function to non-nil arguments only than #(when % (f %))
?
I'd prefer a function that I can comp
. However, #(some-> % f)
doesn't seem better than the solution above.
@jindrichm: there is also fnil
, but it works differently
Another common nil pattern is: (when-let [x ...] (f x))
. It all depends on your context
@jindrichm: how about custom macro?
(defmacro when-ex
([x & args] `(if ~x (do ~@args))))
(macroexpand '(when-ex x (f 1) (g 2) (h 3) ))
;;=> (if x (do (f 1) (g 2) (h 3)))
A macro could do, but a simpler one would suffice. I need to apply a single function to a single argument.
this time is real
(defmacro when-ex
([x f] `(if ~x (do (~f ~x)))))
(macroexpand '(when-ex x f))
;;=> (if x (do (f x)))
What precisely does this bit of the RING spec mean?
the seq of strings bit
interesting aside - has anyone converted the ring spec into a prismatic schema definition?
@rickmoynihan: the http spec (well, http/1) permits multiple instances of the same header name to be sent from either client or server. The seq of strings represents the case where the server received a such a request
@jonahbenton: cool - I get that - I guess my question is, is it referring to a format like this {"Accept" ["application/json" "text/plain"]
whats ambiguous is if it means the seq is in value position... I guess it must
@rickmoynihan: Yes. But that would result in two header entries for Accept
@agile_geek: yes - which is allowed
I think you could do it with one like this:
{"Accept" "application/json, text/plain"}
as the http spec allows comma separated values
in this case the value in the map is a string with comma separated values rather than a seq of strings
@agile_geek: yeah - I know you can do that... I'm just wondering what data structures are valid according to the ring spec
Those two examples
AFAIK
actually reading it again it isn't ambiguous - it does say "These values..."
thanks though
Anyone know why all the core.match examples seem to introduce an extra level of nesting to the item and match-patterns? https://github.com/clojure/core.match/wiki/Basic-usage#vector-types
is there a name for the pattern where i wrap a bunch of functions around each other to modify a map which is a response to an api call? So like middleware sort of but I only have access to responses, not requests. Is that just called a "pipeline" do any notable clojure libs use this?
@gtrak: It is my understanding that its similar to vector destructuring in function arguments: (fn [a b c]
vs (fn [[a b c]]
- the former is a function with 3 arguments, the latter is a function with one argument that is a vector with three elements. So in core.match, [[a b c]]
means “match one thing, which is a vector with three elements”. Do you have a code snippet showing it work without the extra []?
Q about reader conditionals. It looks like the well-known tags are just :clj, :cljs, etc. Is there any thought about a version number?
I may want to build against a newer version of Clojure and polyfill. Example: if reader conditionals had existed in 1.6, we could polyfill clojure.core/update into 1.6 and use the real implemenation in 1.7.
@jjttjj yes, and there are many ways to do this. one common way is with a threading macro- (-> response-map fn1 fn2 fn3) where each of f1, f2 and f3 return the modified response map. this is for cases where the series of operations are statically defined, e.g. by the programmer.
@hlship for platform-specific symbol existence, maybe use resolve? it looks like platform-specific version checks appear to have been discussed as part of the feature expressions proposal- predecessor to reader conditionals- but were considered problematic/out of scope. http://dev.clojure.org/display/design/Feature+Expressions
Hi. I'm sending a bunch of http requests async using http-kit and passing in a callback to handle the response. Can anyone tell me how I ensure all responses are processed before the program exits? Thanks
@timmw each request should give you a promise, whether you give it a callback or not, so you can use the doseq pattern in http://www.http-kit.org/client.html#combined
Ah right. I was thinking that would cause each promise to block as it's processed, but as each promise is in its own thread that wouldn't be the case, right?
right, your doseq code will block on individual undelivered promises. the work on the http-kit side isn't blocked
well, in order to ensure all responses have been processed, you need to deref each promise. dorun won't do that on a seq of promises.
yes, exactly
.. trying to write a function to take a list of sorted joda weekday dates and group them into full (5) weekday subvectors. When weekdays are skipped/missing that whole week should be excluded. It seems to have some likeness to partition-by and take-while. Any help is welcome. Thanks!
@symbit joda time should have a week of year fn, so you could partition on that, exclude groups with less than 5 members, concat the remaining groups and then partition by day of week
@jonahbenton good idea. Thanks. (clj-time.core/week-number-of-year (clj-time.core/date-time 2016 1 14))
@jonahbenton: works thanks for the tip!
@symbit sure thing good luck!
If your sequence went something like Jan-1, 2014, Jan 2nd 2015, Jan 3rd 2016, Jan 4th 2016, Jan 5th 2016 you might get a false positive.
For example, if I have (def app-atom (reagent/atom {:text “some text” :name “some name"}))
, how would I swap just the name?
michaeldrogalis: Is this the best place to ask questions about Onyx, or the Gitter/somewhere else?
That's simply how swap!
works. It takes an atom, a function (here, assoc
) and a number of arguments that should be passed to this function along with the value of the atom.
This is equivalent to (swap! app-atom #(assoc % :name "some other name"))
if that helps.
In general, (swap! some-atom some-function arg-1 arg-2 arg-3)
is simply shorthand notation for (reset! some-atom (some-function @some-atom arg-1 arg-2 arg-3)
.
@lvh: #C051WKSP3 or Gitter, I usually have both open.
(probably because the equivalent you wrote doesn't guarantee that some-function
will get the current value of the atom at the time you try to commit into STM)
@jaen: Interesting. Is this just an optimization, or are the cases where the two expressions give different results?
I'm no Clojure internals guru, but I imagine that with high contention you could get inconsistent results.
@jaen spinlock
Yeah it is, was just confused at first, didn't have to do much low-level threading in my life
Maybe I’m missing it in the docs, but is there a way to turn off shrinking for a test.check test?
@arcdrag: You turn it off per generator, I believe. (gen/no-shrink)