This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-16
Channels
- # admin-announcements (5)
- # announcements (2)
- # beginners (2)
- # boot (3)
- # cider (54)
- # clojure (196)
- # clojure-berlin (16)
- # clojure-brasil (4)
- # clojure-dev (36)
- # clojure-italy (3)
- # clojure-japan (9)
- # clojure-korea (3)
- # clojure-russia (18)
- # clojure-uk (24)
- # clojurebridge (11)
- # clojurescript (414)
- # code-reviews (1)
- # core-typed (4)
- # datomic (59)
- # editors (30)
- # euroclojure (2)
- # events (1)
- # jobs (2)
- # ldnclj (16)
- # liberator (11)
- # off-topic (59)
- # om (16)
- # onyx (33)
- # reagent (53)
- # thejaloniki (2)
- # yada (1)
is there any way for code to detect that it's in the presence of an nrepl thread? I can probably hack thread-bound vars in tools.nrepl namespaces
> (keys @(:session @(resolve 'clojure.tools.nrepl.middleware.interruptible-eval/*msg*)))
(#'clojure.core/*assert* #'clojure.core/*print-level* #'clojure.core/*data-readers* #'clojure.core/*e #'clojure.core/*warn-on-reflection* #'clojure.core/*print-meta* #'clojure.core/*1 #'clojure.core/*out* #'clojure.core/*in* #'clojure.test/*test-out* #'clojure.core/*command-line-args* #'clojure.core/*print-length* #'clojure.core/*err* #'clojure.core/*3 #'clojure.core/*ns* #'clojure.core/*default-data-reader-fn* #'clojure.core/*compile-path* #'clojure.core/*2 #'clojure.core/*unchecked-math* #'clojure.core/*math-context* #'clojure.tools.nrepl.middleware.session/*out-limit*)
(.write (get @(:session @(resolve 'clojure.tools.nrepl.middleware.interruptible-eval/*msg*)) #'clojure.core/*out*) "WAT")
totally works
I've been using (alter-var-root #'out (constantly out)) to work around threading issues
at threads that are not repl threads, or threads not created by clojure, out goes to stdout.
so, this will change the root binding to the current value of *out*
, which is exactly (get @(:session @(resolve 'clojure.tools.nrepl.middleware.interruptible-eval/*msg*)) #'clojure.core/*out*)
bozhidar: Wouldn't this help us with the lack of middleware printing when developing cider-nrepl?
i think we talked about different tradeoffs of managing multiple sessions early on in cider-nrepl
@malabarba: https://github.com/clojure-emacs/cider/issues/460 @bozhidar said "I'm OK with dispatching the (autocomplete) op in the main session for now."
it seems that the biggest gain of using the tooling session was actually that “tooling evals” (evaling the huge inlined Clojure strings), didn’t clutter the special vars set the by actual evaluations
although the problem with blocking evaluation in the main session is real, nobody seems to have complained about it
btw, regarding the logging - I was actually thinking of implementing a special logging scheme in the middleware
at any rate - the idea you discussed for dealing with standard output sounds reasonable to me
@gtrak: btw, we should probably add something in the troubleshooting and pitfalls sections of our README about the standard output
When I run lein repl :headless :port 4000, I'll see 2 java instances in memory. Can anyone explain me why clojure repl needs 2 jvm instances?
I have the name a function in a string and I want to call it, I could use ns-resolve but it requires the name of the namespace. Is there a way to do it with the current namespace, and by that I mean the one in the file I’m located (lexically?)
*ns*
is bound to the current namespace. May I ask what you want to achieve?
@pupeno: clojure.core/resolve
will resolve a symbol in the current namespace, with aliases/etc., you can call (symbol “name”)
to construct a symbol from a string.
@ordnungswidrig: I’m trying to call a function having the name on a string, I’m getting the name from a database connection uri.
@andrewmcveigh: (ns-resolve ‘korma.db (symbol name)) works but (resolve (symbol protocol)) doesn’t. I believe the reason is that calling resolve is trying to resolve the symbol in the namespace that’s calling the function… that is, ns and it’s not being called from ‘korma.db.
The symbol would have to actually resolve in the current namespace for that to work.
Yes, I don’t want to resolve it in the current namespace, I want to write this: (ns-resolve 'korma.db (symbol protocol)) without having to hard-code the name of the namespace that this file represents. Is that possible?
I question that the approach makes sense.
I’m not really sure what you’re asking to be honest, but unless clojure can resolve the symbol in the current namespace, or you give it a namespace you can’t resolve
it.
btw, I agree with @ordnungswidrig , this sounds like a bad idea
@ordnungswidrig: do you have any suggestion?
In the particular case I would dispatch based on the connection uri and map that fixed set of values to the functions in kormab.db
@ordnungswidrig: do you mean with a case expression?
like that.
Or simply use defdb with the right values and lookup the driver classname from the database name.
@ordnungswidrig: so, here: https://gist.github.com/pupeno/bc0363f61e0da2d73da4 you prefer 2.clj instead of 1.clj?
@ordnungswidrig: I am contributing to Korma so that you can more easily connect with a URI, not just using Korma.
yes, however the opts argument is very generic. Why not simply call (defdb my-deb opts)
?
@ordnungswidrig: because Korma doesn’t accept connection-uri, so I’m building that: https://github.com/korma/Korma/pull/317
At least whitelist the symbols, then
@ordnungswidrig: yes, of course, that’s what that if with a set is doing.
yes. The second option has the advantage that you could mangle the opts if necessary for individual methods.
and runtime resolution is always a little fragile Maybe could use a macro generate the second option.
I made a stupid HTTP queue/load balancer https://github.com/joelkuiper/aplomb, probably not something reusable but could be interesting, maybe
@voxdolo: Sounds like what you have is lazy sequences embedded in some larger data structure. pr-str
will usually force evaluation of everything, or you could write a recursive function that walks all the data.
@stuartsierra: yep, that's the situation. I've wrapped the lazy portions of the datastructure in a doall
for now, but would love to be doing something more elegant.
fwiw, I created the data structure, so I have full control over it. I just haven't found a way of forcing the evaluation that doesn't feel bolted on.
@voxdolo: there is no completely general way to do it. So many built-in clojure functions return lazy sequences by default.
If it's your code, you can do things like replace map
with mapv
and sprinkle vec
or doall
elsewhere.
@stuartsierra: okay, thanks for the pointers
@stuartsierra: replacing my calls to map
with mapv
throughout the data structure resolved the issue. Also has the pleasant side-effect of making the whole data structure associative. Thanks again!
You're welcome!
can anyone suggest a good resource for getting emacs set up for clojure dev from scratch?
@logaan my colleague started with this I believe: http://www.braveclojure.com/basic-emacs/
there’s also an article here http://clojure-doc.org/articles/tutorials/emacs.html
@logaan: there's also http://overtone.github.io/emacs-live/ and if you're from vim-land (as I am) then you'd do well to look into https://github.com/syl20bnr/spacemacs
@borkdude: thanks. I noticed braveclojure but was hoping for something that wouldn’t come with a big config repo. I’d prefer to know what’s been changed from raw emacs.
logaan: then just boot up Emacs, configure Melpa, run list-packages
and install cider
@bozhidar, @malabarba: thanks for the tips. I’ll try clojure-mode + CIDER
emacs comes with a package manager built in now? When I was last using it in about 2009 there were several competing package managers.
@logaan: I found checking in my elpa directory in git useful, for when I upgrade libraries and they don't work 😉
btw, there’s also https://github.com/clojure-emacs/inf-clojure if you need just a basic Clojure REPL, with no bells and whistles
thanks. if I hit any issues is #C0617A8PQ the best place to ask for help? Rather than polluting #C03S1KBA2.
@bozhidar: I’d like some clojure related bells and wistles. They’re the main thing attracting me away from a pretty mature vim setup.
@voxdolo: I’ve had bad experiences with viper, evil and vim emulation in sublime and IDEA. Is spacemacs really that much better than previous attempts?
and I generally hit some annoyance within the first 10 minutes of using some other emulation of it
but evil-mode is super solid and I've yet to do even some obscure chording or phrasing that it hasn't been able to do
spacemacs is really just an opinionated set of packages that caters to evil mode and leverages the spacebar for using helm everywhere
logaan, it’s so worth it. soldier through the initial tough bits
@robert-stuttaford: emacs is worth it or spacemacs is?
the former
i never acquired vim fingers, so never needed the latter
I’ve used it before for about 6 months. unfortunately I developed RSI and was left unable to type/work for a couple of weeks. switching back to vim seemed to help.
goodness. my condolences
have you seen the talk by the guy who uses emacs with his voice?
I believe so. I can’t imagine that’d go down well in an open plan office…. though maybe it’d help people come to the conclusion that open plan offices aren’t so great after all
having to deal with the jankyness of paredit.vim is really what’s got me motivated to try emacs again.
emacs’ paredit is solid, and there’s paxedit too, which has some nice additions. there’s smartparens for emacs as well
As long as you don't use it in strict mode it's surprisingly easy to get a useful amount of structural nav into your workflow
@logaan: I found the brave clojure start worked pretty well, I used it to get up and running when brand new to both emacs and clojure.
@shaun-mahood: It looks very well written, but I’m going to try and avoid setups that require adopting a heap of config up front. I’m having decent luck so far just following the cider instructions.
@logaan: paredit.vim is bad 😕 https://github.com/guns/vim-sexp with https://github.com/tpope/vim-sexp-mappings-for-regular-people is a much better experience for vimmers, imo.
I only left vim for the better cider integration in emacs, personally. Could never quite get a satisfactory clojure setup going there.
thanks to everyone for their help. I’ve managed to get a basic setup going from scratch
Spacemacs has converted this vim user to Emacs as well. It’s fantastic and getting better with each release.
Say you want to bundle some clojure code into a non-clojure project that uses maven to package everything up. What options are available for doing that?
if it's all integrated in the same project, you can use clojure-maven-plugin
or maven-clojure-plugin
or whatever it's called :)
if it's separate, just create an artifact from the clojure parts, then depend on it from the java project
is it possible to capture the namespace of where a macro is used which is itself used inside another macro? right now i get back clojure.core as the namespace which is not what i was hoping for
(defmacro dbg [body]
(let [{:keys [line column]} (meta &form)
ns (str *ns*)]
`(let [x# ~body]
(println (with-out-str
(print (str ~ns ":" ~line "," ~column) (quote ~body) "= ")
(pp/pprint x#)))
(flush)
x#)))
What are good examples of clojure codebases for learning? For a person, who has about a 6 months of clojure experience and wants to do more and also would like to train other people too. clojure.core is an interesting example and I want more good examples
hmmm nah... still got the same problem. appears to me that the outer macro executes the inner macro inside clojure.core namespace. probably over a map
@abtv: I’m not sure how much you’d learn but you should be able to handle https://github.com/logaan/vlad core.cljc is a couple hundred lines