Fork me on GitHub

I see it in local scope for picking out options.


(let [things ({:a [1 2 3], :b [4 5 6]} opt)] ...)


newb here w/ an aot question. i'm compiling a (defrecord Foo ...) producing a jar containing the Foo.class then depending upon that jar from a java project i can successfully load Foo.class (ie, Class.forName("Foo")) dynamically from the java project but attempting to compile/`javac` statically against Foo (ie, import Foo from java), i get a compile error that the symbol can't be found


javap Foo.class shows nothing suspicious. maybe something obvious, but i'm banging my head here..


lotta variables there 🙂


Is there a package? I can’t remember for sure, but I think Java disallows using the default package.


ha, there is a package

Alex Miller (Clojure team)02:04:23

java doesn't disallow it, it's just discouraged

Alex Miller (Clojure team)02:04:41

maybe post the full compilation error?


i used default package just to keep the question shorter 🙂


next q: is the classpath properly set for the javac command?


Error:(6, 30) java: cannot find symbol
  symbol:   class Foo
  location: class com.example


it seems clear it’s properly set for the java command (since you’re able to access it via reflection), but it could be improperly set for the javac command


yes the javac -cp ... is set


i'm able to link against other .class files


it makes me thing the .class generated by compiling the defrecord is special somehow


to my knowledge, it is not


this yields a successful compile/javac:

import com.example.*;
class Bar { public static void main(String[] args) throws Exception { System.out.println("hello"); } }
this doesn't:
import com.example.Foo;
class Bar { public static void main(String[] args) throws Exception { System.out.println("hello"); } }


this compiles and runs w/o exception:

import com.example.*;
class Bar { public static void main(String[] args) throws Exception { System.out.println("hello"); Class.forName("com.example.Foo"); } }


Are you overriding the classname? class Foo


oh good question -no ..


(i just edit my slack examples)


Like I said, the last one is mostly irrelevant. It says nothing about the compilation.


the one that succeeds of course doesn't if i get the javac -cp wrong



$ javap com/example/Foo.class 
Compiled from "model.clj"
public final class com.example.Foo implements clojure.lang.IRecord,clojure.lang.IHashEq...


Yeah I dunno. Would probably need a full example.


Good luck 😕


hmm actually i might be on to something


i think i have package and a class w/ the same name


ok that seemed to be it


however -- this seems like it'd be a common type of collision in clojure compiles ??

raaon02:04:34 i (defrecord Foo... within (ns com.example)


compiling yields a com/example.class and a com/example/Foo.class


a javac / static compile finds import com.example.Foo and doesn't like it b/c com.example is a class ...this explains why the .forName("") worked and not the static compile


but i guess i'm having trouble seeing why this wouldn't be a common thing


...okay so i do have a (:gen-class) on the (ns com.example) so perhaps a slightly or much less common sitch?


after many years of java coding i did not realize you couldn't safely have a package and class w/ the same name

^bad for javac apparently


removing the (:gen-class) fixes the issue i guess the lesson is don't :gen-class ns's containing defrecord's?


...revision: explicitly specify non-conflicting :name to gen-class will solve it too

Suren P04:04:40

Hey guys, I asked thi sin disc but none seems to know what's going on. I'm getting:

SEVERE: Error creating DB connection for {:classname "com.mysql.jdbc.Driver", :subprotocol "mysql", :subname "//<ip>:3306/proj_dev", :user "root", :password "A<censored>"}
java.sql.SQLException: No suitable driver found for jdbc:mysql://<ip>:3306/proj_dev
for migratus when running lein migratus migrate the db is completely empty, first time trying to migrate anything
With this in project.clj
  {:store :database
    :migration-dir "migrations"
    :db {:classname "com.mysql.jdbc.Driver"
          :subprotocol "mysql"
          :subname "//<ip>:3306/proj_dev"
          :user "root"
          :password "*"}})
I'm not sure what I'm doing wrong I have connected to the server with MySQL Workbench

Suren P04:04:58

I'm trying to connect to a Google Cloud MySQL instance...

Suren P04:04:09

any ideas?


Hi every one, I wrote this utility as an alternative to with-redefs such that the redefinition is done only on that thread and not others (ie, the global definition remains the same and redefinitions are per-thread). This is a fork from @gfredericks’s original solution Would appreciate if you could check it out to suggest improvements/corrections: cc @h0bbit


Hmm. Has anyone else noticed a really slow startup times with lein repl when using JDK12?


My REPL timeouts almost always with JDK12, maybe 1 out of 10 succeeds to connect. With JDK10 it works normally


try clojure 1.10.1-beta1


there was a performance regression regaring user.clj that 1.10.1-beta1 addressed:


Oh, that has to be it! Cheers


Yeah, I can confirm that after changing to 1.10.1-beta1 REPL starts up normally


hi all, i'm looking for a good API client HTTP project for reading the source code and design as muster


do you have any example in the clojure ecosystem and lib in the opensource word? like it could be dunno, any library with rest-client


Anyone using nginx-clojure and got it running with openjdk 10+? Project doesn't really seem maintained anymore.


I use nginx-clojure but i think it doesn’t handle java versions above 8 right now. I don’t think there’s much active development happening but it’s been stable for us.

👍 4

Or perhaps someone can advise a better deployment method these days, with high performance?


define high performance? what's the use case


Real time bidding, just want to squeeze out as much performance as possible, and nginx-clojure had decent benchmarks.


most of the time aleph or jetty is good enough. Not sure nginx-clojure performs better at all


Hey guys, I just downloaded clojure via the installer for windows (it downloaded as powershell module). I need help getting it started.

Alex Miller (Clojure team)12:04:56

Please ask in #clj-on-windows for help...


aleph also scores better than openresty (same models as nginx-clojure I think) on other benchmarks, anyway I bet the kind of platform you're building will likely not have a bottleneck at this level

👍 4

Anybody have experiences to share using Akka with Clojure? I found a couple of small wrapper projects which look inactive. My main concern would be around the requirement that actor classes be serializable, so I'd think you would have to be cautious about typical Clojurisms like grabbing state in a closure.


I was trying to point some of my users at the Clojure documentation to show all the options for spit, and hit a brick wall. The spit doc string does not list them, and even if they are resourceful enough to look up the entry for writer that does not list them. I basically would need to teach them how to bring up a REPL and spelunk through the source code in order to get a definitive list. And they are mostly not software developers. This seems… unfortunate?

Alex Miller (Clojure team)16:04:14

jira welcome, I don't think there is one I'm aware of


OK, I created one. I forgot that I even had an account on the JIRA. Thanks! Hopefully it was formatted correctly and sufficiently informative.

Alex Miller (Clojure team)19:04:20

thx, I added a patch

🎉 4

Wow, that was fast! 😄

Alex Miller (Clojure team)20:04:17

easier to do it now before I forget about it :)

Braden Shepherdson18:04:24

I'm looking for a way to manage state reactively, where the crucial thing is that invalidations are eager and computing the new value is lazy (ie. on deref)

Braden Shepherdson18:04:34

I was thinking an agent with for each chunk of state I care about, that eagerly invalidate their listeners. but how can I override the deref behavior?


does this match the semantics of a cache at all? with core.cache you can easily get custom access / lookup behaviors


(while storing the cache itself in an atom, agent, whatever's apropriate)

Braden Shepherdson18:04:04

hm, I wasn't thinking of it in terms of a cache at all. it's not a typical cache, but perhaps I could (ab)use hundreds of 1-element caches for this.

Braden Shepherdson18:04:36

the use case is a large reactive system, containing many hundreds of entities and links between them, but where only a handful of entities are "live" at any given time.

Braden Shepherdson18:04:16

if the invalidations are eager, the views for the few things that are live will know they need to rerender. meanwhile, the rest of the world might be invalid but that's harmless.


hmm, sounds a lot like what react does under the hood actually

Braden Shepherdson18:04:16

not dissimilar in principle.


what's the difference between "hundereds of 1-element caches" and "a cache with an index"

Braden Shepherdson18:04:02

depends on whether invalidation happens at the entry level or the cache level, I guess. I'm reading the core.cache docs now.


I guess you'd need it loop it through - the cache forcing function would need to look up its data sources in the cache and invalidate it's descendents? now that I think about it you probably want a proper reactive system and not hacking it direclty out of cache / agent building blocks(?)

Braden Shepherdson18:04:20

well, I mentioned agents because that's what it felt like when I was vaguely thinking about it last night. but I think there's a bunch of extra bookkeeping to do that pushes me to use a default implementation. I'll probably end up building each reactive block out of a handful of refs I transact over, I guess.


it uses rxjava iirc


it uses rxjava, futures, and core.async in various examples


react, if I understand, doesn't actually use caches(so avoids figuring out cache invalidation), but diffs the virtual dom to determine what needs doing


yeah, by extension you could use it to turn data dependency in a data flow app into smart invalidations, but that's still a stretch I think

Braden Shepherdson18:04:17

for my purposes, the wiring of dependencies is explicit, so I don't need to infer it. I just want to avoid having to unwire and rewire things as the user navigates.

Braden Shepherdson18:04:56

anyway, I'm just building a prototype, so I'll just hack something together and not sweat it too hard for this first POC.


Is there any way to dynamically un-extend a protocol?


assign method implementations that all throw unimplementederror?


use-case: I have a default java.lang.Object implementation of a Foo protocol


then I extend it to clojure.lang.Seqable in the REPL


afterwards I realise I don't want that implementation to include hash maps, so I change that to a clojure.lang.Sequential


how do I disassociate Seqable so that calling a Foo method on a hash map falls back to the default Object implementation?


(without restarting the entire REPL)


@qythium the extension of the method is stored with the protocol implementation (iirc in the var itself or its metadata) and can in theory be removed, I don't know if there's anything that would be portable though


@qythium this should be enough info for a short term hack, but no promises it would work with the next clojure release

(ins)user=> IFoo
{:on user.IFoo, :on-interface user.IFoo, :sigs {:frob {:name frob, :arglists ([this]), :doc nil}}, :var #'user/IFoo, :method-map {:frob :frob}, :method-builders {#'user/frob #object[user$eval145$fn__146 0x42f33b5d "[email protected]"]}}
(ins)user=> (extend Object IFoo {:frob (fn [x] [:obj x])})
(ins)user=> IFoo
{:on user.IFoo, :on-interface user.IFoo, :sigs {:frob {:name frob, :arglists ([this]), :doc nil}}, :var #'user/IFoo, :method-map {:frob :frob}, :method-builders {#'user/frob #object[user$eval145$fn__146 0x42f33b5d "[email protected]"]}, :impls {java.lang.Object {:frob #object[user$eval162$fn__163 0x3e14c16d "[email protected]"]}}}


usually protocol / interface / multimethod changes are the one reason I do an unconditional repl restart, and I try to work on my design in such a way that those would change extremely rarely (which makes sense, as they are all meant to be top level entry points for other code)


tried doing (def Foo (update Foo :impls #(dissoc % clojure.lang.Seqable))), but that didn't work


guess I'll just have to restart the repl.. had lots of "testing data" state built up from evaluating commented forms which I didn't want to lose, but that's probably another sign of general sloppiness


I'd suspect alter-var-root rather than def/update to be the right path, if anything worked


hmm, that doesn't do the trick either

Alex Miller (Clojure team)20:04:09

protocol choices get baked into per-call-site caches so it's probably difficult to do this fully without restarting your repl


Hello, I’m having some issues working with mutable Java arrays and can’t find what is going on. This code is supposed to return 5 but returns 0

(let [m (to-array [0 0 0])
      _ (for [i (range 3)]
          (aset m i 5))
      x (aget m 2)]
;; => 0
Now, when I eval it one form at a time it correctly returns 5
(def m (to-array [0 0 0]))
;; => #'user/m
(for [i (range 3)]
  (aset m i 5))
;; => (5 5 5)
(aget m 2)
;; => 5
Maybe I’m missing something obvious :thinking_face:


classic laziness. for returns a lazy collection and is not a good choice for performing side effects like mutating an array. What you are seeing is that nothing is realizing the collection so no work is ever done. the result is that the original array contains 0s rather than 5s


right, of course, thanks!


do you know the best way to fix it or want to ponder/work at it some more?


(or already know the answer :)


I was going to try a doseq, is that enough? :thinking_face:


that's what i would do


cool!, thanks 👍


> if the invalidations are eager, the views for the few things that are live will know they need to rerender. meanwhile, the rest of the world might be invalid but that's harmless. @braden.shepherdson isn't this how some CLJS view libs work? E.g see Reagent (`reaction` and ratom), Rum (reactive components and derived atoms), hoplon+javelin, etc.


hey guys, whats the cleanest way to append something to the end of a vector within a thread last macro


(->> v (conj e)) and (->> v (concat [e])) don't work for obvious reasons


am i stuck having to create a let binding for this?


Are there any compelling reasons to prefer the loop and recur pattern over recursive function calls?


@yedicould be the case for as-> instead of ->>


@yedi I don't understand why you say your first example doesn't work, this works for me:

(let [c [1 2], v 3] (->> v (conj c)))
=> [1 2 3]


Oh, v is the vector not the value. Never mind.


@yedi ->> and as-> are written so they can be nested inside ->


you can use -> at the top level, and use ->> / as-> for parts of the pipeline inside that need to use the tread-last behavior


user=> (-> [] (conj [:a 0]) (->> (into {})))
{:a 0}