Fork me on GitHub

is it possigble to do the same thing with tomcat, I want to "fire off a tomcat from inside cloljure, passing it a ring handler"


Is there any good library for async jdbc in core.async. now I use thread for jdbc operate. I'm using MySQL.


there's no libs for async jdbc period because jdbc can't actually do async


using thread inside core.async is a great idea, best option IMHO


it would be awesome if the db driver actually supported async directly


I saw there's some library like postgres-async. I'm not sure how it works


if it's jdbc it's just using threads, it can't do anything better


if it's not jdbc, then it might be cool


using thread directly may cause problem IMO, maybe a thread pool is better?


thread uses a pool


😂I'll take a look


(defonce ^:private ^Executor thread-macro-executor
  (Executors/newCachedThreadPool (conc/counted-thread-factory "async-thread-macro-%d" true)))


that's what thread uses (via thread-call)


i'm confused as to why (def (gensym) ...) is telling me gensym isn't returning a symbol when (symbol? (gensym)) => true?


because def is a macro, it doesn't evaluate that argument


(gensym) when unevaluated, is a list containing a symbol


ah, ok. thanks justin


you need to write a macro to def from gensym


well, considering the use case i'm thinking there may be a better option than def


Maybe (intern *ns* (gensym) :value)


also, in general, if you aren't accessing the value from code written in a file, it's much more convenient to just use a hash-map instead of using a namespace via def


it is a much nicer api to work with


i have a library that currently requires the user to define a global atomic map, pass it to a function, and then pretty print it. i figured i should automate that with a macro so they can just call one function that does everything plus returns the map


OK - why not let the user decide where to put the map?


i'm toying with making it a little more dsl-ish


anyway, just an observation, it's a lot easier not to do automated things with namespaces, and there's few benefits to doing them with namespaces in my experience


but that's just my opinion of course


i'm just saying, were i to do this, it seems calling def inside a macro doesn't make much sense, right?


i'd rather have the map bound locally and then not need gensym. then i can return a copy and have the user decide what they want to do with it


anyway, to solve the macro issue i'd just need to unquote splice it right? like (let [store @~(gensym)] (def store (atom {})))?


err wait...without the deref i think...


ah! sorry, i got it. i don't use macros hardly at all 😛


obviously need to put a let on the outside of my quasiquote for something like that


(defmacro random-var [value] `(def ~(gensym) ~value))


or with a let block

(defmacro random-var [value] `(let [sym# ~(gensym)] (def sym# ~value)))


the # suffix is needed because ` doesn't like unqualified symbols, even in binding positions


i got it to work by just putting the let outside the quasiquote (everything else is in a do block)


but thanks, that's good to know for the future


it isn't a good style that def isn't on the top, You might be able to find a better solution.


according to the scene


hello! I am trying to use Immutant.scheduling to run something periodically. However this

(let [t (clj-time/today-at 11 00)]
  (schedule foo
    (-> (at t) (every 1 :hour))))
gives me an error: No implementation of method: :as-time of protocol: #'immutant.coercions/AsTime found for class: org.joda.time.DateTime any thoughts? I am figuring t cannot be passed to at here, but am not sure why! Thanks


@raheel Are you requiring immutant.scheduling.joda?


oops. I was not! thank you, that does fix it.

Björn Ebbinghaus07:05:30

Hey, I have Clojure and Java code side-by-side in my project. Is there a leiningen plugin for static code analysis like kibit or eastwood for java code?


Do you need something for Java only or Java and Clojure at the same time? If it's Java only, you could use Findbugs, or Sonar if you want to use a full-fledged tool.

Björn Ebbinghaus08:05:11

georgberky: Both would be great. I didn't find a Findbugs plugin, which would be great. It doesn't have to be a full blown tool. just a small report in the terminal. Do you know a practically way to integrate findbugs into leiningen?


Hmm, findbugs seems to be limited to Java code, so not sure if you can find a tool that can do both Java and Clojure. But maybe Sonar is an option for you. They seem to have a Clojure plugin.


At least you'd have both Java and Clojure in the same UI, even if they're not handled by the same tool.


hey guys, can someone point me to a Dockerfile that installs clojure. I don't want to use FROM:Clojure


@blane if you build an uberjar you don't need your Dockerfile to install clojure - a jdk will do just fine, e.g. or


@blane, people often build the uberjar and build the docker image around that


then there's no need to install clojure, all you need is a jdk


disclaimer: I'm not a fan of docker so I may be all wrong


this is not clj question but i cant seem to find solution and you are pro developers someone surely must know the answer guys i've got sql question hope someone can help create table forums( id int auto_increment primary key, name varchar(50) not null, description varchar(250), ownerUsername varchar(30) not null, -- owner creationDate datetime not null, -- creation date locked boolean not null, type varchar(30) not null, parentForumId int, -- nadforum, deleted boolean not null, FOREIGN KEY (ownerUsername) REFERENCES users(username), FOREIGN KEY (parentForumId) REFERENCES forums(id) ); this is my table i have tree like structure forum1 has (forum 2, forum 3( has forum 4, forum 5)) i wanna make statement or function that would delete all children if parent is 'deleted' (deleted set to 1 ) i am using mysql and i kinda saw something i could use i am just not sure how to make use of it


Is there a cond-as-> threading macro?


@lepistane if you just want to perform delete, the approach with foreign keys might work (I didn't try that). However, for more efficient approach usable for querying too see "Nested Set Model" (e.g. - relational databases usually suck at modeling tree-like structures but I guess that's the best model you can use with MySQL.


jumar: Yeah, doesn't seem to exist. I suppose cond-> with #() is a fine replacement


@jumar i will read this i mean worst case scenario i will make recursive function in java DAO class that sets deleted =1 to all children until there are no children it will be unefficient as.... but u know


@jumar tnx for the read it's way over my head (i am newbie) i will get back to it in a month when i finish this and now to the recursive functions!


Hey, folks In example below if I replace #'home-routes to home-routes nothing changes, program still works. What is the reason to use var reader macro in such places?

(def app-routes
    (-> #'home-routes
        (wrap-routes middleware/wrap-csrf)
        (wrap-routes middleware/wrap-formats))
        (error-page {:status 404
                     :title "page not found"})))))


@armed it still works, but you will loose the ability to reload the routes definition without restart, which is quite handy during the development


@jumar thanks, now I see why sometimes I had to restart repl.


you still need to use wrap-reload middleware, though - I'm not sure what's your setup, but Luminus will generate the code automatically for you in dev-middleware namespace


namespace on a keyword is a different thing than namespace on a var, correct? For a keyword it is just a string, there may or may not be a physical namespace object by that name.


ie, you can’t get a list of all keywords for a given namespace


because they aren’t registered with the namespace like vars are. Do I have this right?


Aanother question related to reloading, have any of you any experience in hot code reloading in non-web server code? I tried implementing the same code as in wrap-reload, but it does nothing.


@vargaradu not sure about wrap-reload but you can certainly use tools.namespace/refresh directly for hot code reloading -


@mccraigmccraig I just tried that, but i keep getting java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set Note: I am using mount to start stop my components, and am calling this refresh function right before I receive an async message (via rabbitmq/langohr)


i don't have enough context to understand @vargaradu - what's the stacktrace of the exception you are seeing - and are you hooking mount's stop/`start` around tn/refresh like this


Thanks @mccraigmccraig , I was looking for something like that, dunno how I missed it 🙂


Doesn't look like a lot of activity in the CLR channel - anyone here using clojure/CLR or have an idea where that crew is hanging out?


mattyulrich: I've written a 25K lines clojure-clr project.


Now migrate to Clojure Luminus


I just missed a hidden ArityException that made it to production, how do I eliminate this from happening? it seems that those should be able to be caught at compile time, no?


@alexmiller Is it not recommended to mix ‘n match reducers and transducers like:

(r/reducer [1 2 3] (map f))
instead of
(r/map f [1 2 3])
Due to differences between rfn and transducers? See:


with threading macros and apply I can think of scenarios where the compiler couldn't enforce it


@dpsutton ah, it was in ->> now that you mention it


a test would expand macros, right... I suppose I could just write a test that it's always called with the right arity...


write a test to make sure what ever is producing the values always returns the right data?


that too, I struggle sometimes with writing tests with heavily effectful code, but that's a good point


yeah. but gives a reason to try to separate the two


how is clj clr? is it getting better/more viable ?


I dunno - was looking to try it out but I can't get it to run as of right now. Hoping someone here may be able to provide some guidance.


if you're wanting to get into Clojure CLR, I recommend downloading this:


it's basically lein for Clojure CLR.


using that I was able to get it up and running in a few minutes.


my friend made windows app which i wanted to make feature in clj then i found out about clj clr


cool.. I'll take a look at that..


I spent the last 10 years working at a Java shop and therefore used clojure for all my personal tooling/testing/poc stuff.


still needs work to better integrate with the .NET ecosystem, but I use it daily! feedback and PRs welcome!


lol and the man himself appears


Just switched to a .net place


Hoping to try and get a bit of that back.


@tbaldridge s u m m o n e d


i will take a look, tnx for link


so, @nasser, to use this with microsoft clr may need some work?


nostrand itself is designed to work with mono, and i test on osx


microsoft’s clr env is set up differently, and depends on visual studio a lot more as i understand it


but nostrand exists because clojure is primarily a library and not a command line tool


so it depends on what you want to do with it. if you want to integrate it into a microsoft clr project as a library, Clojure is on NuGet already. if you want to use nostrand’s dep management and command line tools, its going to take some tweaking.


right.. I should investigate what it does with Mono first and then see what the parallel in microsoft might be... I pulled the NuGet module, but can't run the repl (dep issue)...


the Clojure.dll i use in nostrand is patched, too. its taken from


nostrand also implements its own repl, which i am on the fence about keeping


which clojure repl did you try and use?


cool - maybe I'll try that.. I'm getting a "System.IO.FileNotFoundException: Could not locate clojure.core.server.cljc.dll or clojure/core/server.cljc on load path"


The 1.8 from NuGet - just pulled the extracted dlls and executables to a separate place and tried to run Clojure.Main.exe - not sure if that's the appropriate way to get it to find all requisite assemblies or not.


hm, clojure.core.server should be on the load path. i havent pulled from NuGet in a minute, that might be a bug


Well - I'm "new" in returning to microsoft-land... So, it's possible that I'm not getting the right assemblies together. Is everything supposed to be in that Clojure.dll ?


hi! can't compile project with [metrics-statsd "0.1.8"] and [org.clojure/clojure "1.9.0-alpha16"]. if I put [org.clojure/clojure "1.8.0"] everything works fine. i suspect that [""] in metrics-statsd can cause such error. any suggestions?


here is the stacktrace


that stacktrace is produced by (require '[metrics-statsd.core :as statsd])


@mike1452 I just downloaded that metrics-statsd jar, and it's a rascal. It contains AOT compiled classes, which is what's causing your headache. I'd file an issue with them to fix and rerelease their jar.


To get you unblocked, you're going to want to delete the jar from your local .m2 directory, clone their project and do lein install after removing their AOT directives (the direct linking is not the culprit here).


@ghadi thanx for advice


clojure jars that contain AOT code make lots of headaches


first time met this problem.


Hi, I'm trying to manipulate an application-state-atom for use with om... and I'm trying to reason about how I can insert-nest comments into the atom... since if the datastructure is right, om-next can just do the recursive query like a champ...


why exactly does AOT cause headaches? i’ve read that several times but i don’t know the mechanism


Ahead-of-time Compilation


@wiseman when two different clojure versions compile code, they aren’t going to aot compile into 100% compatible results


(not to mention problems with generating a new Interface everytime you run defprotocol, and a new class every time defrecord is run etc. leading to weird errors if things are compiled separately or later get recompiled but maybe not everything got recompiled ….)


ah, that makes sense. thanks!


It can work fine when AOTing your own project locally. Just never distribute AOT'ed jars unless you are really really careful


figwheel seems to be serving the public/index.html file from one of the libraries I use. How do I prevent the resource directories from being merged like that? Or does anyone know of another figwheel setting that can prevent it from using that html file?


@ghadi your advice works! thanks. but additional steps were required: :aot [metrics-statsd.reporter] and point out the same version of clojure that i use [org.clojure/clojure "1.9.0-alpha16"]


just remove aot entirely


without aot it produces another error:


in ns metrics-statsd.reporter, there some code which requires aot


if they do their requires properly they can generate that class without needing aot


How can I get the current runtime profile ? I mean i want to know whether I'm running on dev or production ?


An AOT uberjar seems safe enough to distribute


How do I isolate my resource files from those of the libraries I use? Apparently the public/index.html file from one of them is being picked up and served by figwheel since I'm not using one.


Do I have to change the name of the directory I use from public to avoid the conflict, or is there a better way to handle that?


on the other hand, you can run an app (even an app that needs to be launched from inside another java app) without using aot, thanks to clojure.main already being byte compiled


@lxsameer I use [environ "1.1.0"] to work with different profiles


I’m at a loss, I am trying to use (in-ns 'myapp) in a lein repl and nothing can be resolved and there are no errors before the unresolved symbol error when i attempt to use my namespace


any common solutions?


interesting, why use one versus the other then? (`ns` vs in-ns)


in-ns is a low level function that switches to an ns and creates it if it doesn’t exist


I don't think I've ever had a legitimate reason to use in-ns, I'm sure they exist...I've just never needed it


the specific thing that causes most of the problem is that it doesn’t call clojure.core/refer-clojure - which you can call btw


very good to know, thanks guys


but usually what you want is to get your namespace loaded from source, which means using require, potentially with the optional :reload arg


what's the most idiomatic way to define a private function? letfn? let?


I know letfn exists, I scarcely see it used


letfn is mostly useful when you want mutually recursive functions that are not at namespace scope


you can’t do that in a straightforward way with let


Gotcha. I had a hunch it was "special" in some way considering how infrequently I see it 🙂


right, let is more flexible, and you can just use fn inside let, that’s usually enough


Got it. Thanks once again @noisesmith


@kzeidler if you're just defining an ns private function, use


Hi I am trying to update metrics-clojure which is a wrapper around dropwizard metrics, to v 3.2.2. However, someone added another method name time in Timer. Now there is one method that takes Callable and another that takes Runnable. When I run the tests, I get this Reflection warning: Reflection warning, metrics/timers.clj:120:3 - call to method time on com.codahale.metrics.Timer can't be resolved (argument types: unknown). I tried to add a type hint to make it go away, but it didn't work. Anyone have an idea for how to resolve it? `(defn time-fn! [^Timer t ^Callable f] (.time t (cast Callable f)))`


if it's a "private" function, as in you want a function only for a particular scope, then let, like @noisesmith recommended


@jeffmad I don’t know the right way to do this, but if you wanted to force it to pick a specific method, (reify Callable (call [this] (f)))


also note private is determined by metadata so you can use metadata to mark most things private. though i believe you can still get at the var if you call it directly


something defined with defn / fn is both callable and runnable of course


ok that is cool. Thank you. @noisesmith that makes it clear since function implements both. I'll try it.


@tanzoniteblack Interesting. The function is just a named selector with no meaning outside the context of some accessor function. I was taught in Scheme that any indexical accessor functions should be abstracted to have a name, like (e.g., in Scheme): (define foo cadr).


Would defn- or let be more appropriate in that case?


I’d use let if it is never meaningful outside the let block


the real answer is to just do everything in one giant let block


@zylox clearly the let block should return a single dwim function


i mean preferably avoid return values, ideally the memory artifact after you call some native code to violently kill the jvm will contain the answer you were looking for and can be read up by a simultaneously running program


(ok this monday might have gone a bit too late already...)


zylox: so here is the organizational challenge. It's not a huge deal, but it does conflict a little bit with the best practices I picked up in a (Java-based) data structures classes. If make-foo and update-foo are both functions that select a :foo value, then foo can be defined in a let block that declares the selectors for each of those functions. But then of course if the interface changes, then the selectors for every function have to change, making that special ns-only defn- form sound quite appealing


I'm just wondering what the conventional way of operating on some nested state-machine-like object is in Clojure, since normally in object-oriented languages these would be scoped to private vars of an object with methods for getting/updating the data 🙂


If all make-foo and update-foo do is access :foo on some data structure, then the typical idiomatic thing is to just use a hash map and not define any special functions. If you need something specific that doesn’t match the behavior of a hash-map, then define some deftype that implements the interfaces / protocols that best describe the data structure - use the good parts of OO for what they are good at


using let to define a bunch of secret accessors and updaters as a pseudo-object is never really the right thing in my experience


if you pick the right interfaces, people can use the existing data functions in clojure seamlessly with your data type


this namespace is a great example of implementing a data type for clojure:


That makes sense to me. In Scheme it's conventional to use sequences as interfaces, so it quickly gets pretty unreadable if you're not defining a mini-dsl for your abstraction barrier. e.g. "define color as the fourth element of foo". But I guess the idea of deftype is to cast those accessors as static, fixed metaproperties of the data rather than, not another datum within the data. Am I understanding correctly?


the accessors are defined on an interface, which is an abstraction that allows polymorphism


code will be written to use those interfaces, and thus will simply work with your new data type


(as long as your data type is well behaved for the expectations of those interfaces, of course)


your type is known to implement certain interfaces, and that indicates that the methods making up the interface (including accessors etc.) are available


:frown: defonce still doesn’t work with a doc string


Remind me how to mutate foo? I seem to remember Clojurescript uses destructuring to apply the value returned by inc-b

(def foo {:a {:b 2}})
(defn inc-b []
  (update-in foo [:a :b] inc)