This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-28
Channels
- # aws-lambda (2)
- # beginners (49)
- # boot (49)
- # cider (7)
- # clara (1)
- # cljsrn (4)
- # clojure (199)
- # clojure-android (49)
- # clojure-dev (1)
- # clojure-greece (4)
- # clojure-italy (3)
- # clojure-nl (4)
- # clojure-norway (5)
- # clojure-russia (78)
- # clojure-spec (22)
- # clojure-uk (18)
- # clojurebridge (2)
- # clojurescript (252)
- # core-typed (2)
- # cursive (11)
- # data-science (1)
- # datascript (2)
- # datomic (38)
- # devcards (1)
- # flambo (3)
- # hoplon (10)
- # immutant (2)
- # jobs (3)
- # luminus (1)
- # lumo (2)
- # off-topic (8)
- # om (3)
- # onyx (29)
- # parinfer (1)
- # pedestal (4)
- # portkey (13)
- # re-frame (13)
- # reagent (6)
- # ring (3)
- # ring-swagger (15)
- # schema (2)
- # spacemacs (4)
- # test-check (4)
- # untangled (46)
- # yada (2)
I still struggle with this... the docs are almost recursive about these things... I'd like to include a single function from a library in my namespace, and give it my own name
@matan https://gist.github.com/ghoseb/287710/#file-ns-cheatsheet-clj-L43 - this?
@not-raspberry thanks for the example code
is there no one-liner for it? looks like the line relies on the preceding require
up there
@matan AFAIK (:require ...)
works just a normal require, but can be placed "declaratively" inside a (ns ...)
.
@not-raspberry thanks for your help!
treat that as syntax
Lesson learned: don't read the docs 🙂
Question. I have a database connection (hikari-cp) that I'm currently using a future to get the datasource so i don't have to wait for the connection. But now I need the ability to change the connection information and reconnect. I'd like to use an atom for that but using an atom of a future seems weird. Is there a better option? I could use an agent but I like that the a future blocks on a dref where an agent just has a default value.
it almost seems like the convenient thing would be a construct that implements the protocols for deref, and had the ability to change from ready status to pending
but I haven’t deeply considered the implications of that…
for a beginner it probably just suffices to say we have nothing that behaves that way, and the simplest thing is to do nested deref of a future inside an atom @@db-conn
@noisesmith thanks!
@kkruit @noisesmith I was recently playing around with something like this:
(defn refi [k]
(reify
IPending
(-realized? [x]
(not (nil? (get-in @db [k :o]))))
IDeref
(-deref [_]
(if-let [o (get-in @db [k :o])]
o
"pending"))))
@john Thanks, I almost get it... I haven't done a lot with protocols yet. I'll save that for later, if it rubs me wrong when I come across my double dref again.
@john that breaks this use case as it never blocks on deref
also it doesn’t differentiate something that never started from something not ready yet
(which may be OK, but is worth pointing out when compared to futures)
right - but there’s nothing in clojure that is dereffable and can freely go from realized? to not-realized?
@noisesmith my above code was not built for @kkruit's problem. I was just tossing it up there to give them a starting point. And on the CLJ side, you'll want to implement blocking
I'd be OK with derefing an atom an a future inside.
But you can see that with the above reification, you could construct a kind of double deref system yourself
how would you use a collection as a "rest" argument for a function, such that each element of the collection becomes, or is treated as, one argument to the function?
apply
(apply + 1 2 [3 4 5]) => 15
I have some more info on the issue I’m having. It’s an Electron project so there’s a nodejs side and a browser side. The nodejs side has (:key map)
and works fine. The browser app doesn’t. The only difference I can see is the compiler target. I started from scratch with a lein template this time. The template is electroncljs
.
It works from a figwheel repl…
@noisesmith thanks!
There it is... I was registering the callback fn before the app was ready.
ahh - so its getting functions called that don’t exist yet
@jeff.engebretsen what I do for this in my app is have the dispatch function check to see if init is done, and if yes it calls the callback, if no it adds the input to a list of messages to act on later (but I don’t have a setup where callbacks would be called before even basic clojure.core stuff is available - that’s trickier)
It's called with a keyboard shortcut then file select. So it's well after setup.
Not sure what happened. I didn't think there would be closure issues like that. But waiting until the app ready callback to register my listener fixed it.
Maybe because my callback was an anonymous fn?