Fork me on GitHub

@qqq Clojurescript projects and tools like will connect (transpile) your Clojurescript code to a node.js host. You can also call node.js libraries.


hm, i enabled reflection warnings on my project and i'm getting one i don't know how to interpret:

Reflection warning, /tmp/form-init4283907053113722510.clj:1:903 - call to static method invokeStaticMethod on clojure.lang.Reflector can't be resolved (argument types: unknown, java.lang.String, unknown).
any ideas? can i get a full stack for that warning?


do reflection warnings happen at compile time or run time?


compile time


@bronsa that's what I thought too, the 'full stack for that warning' confused me


(defn rnd-f-arr [n]
  (let [random (java.util.Random.)
        x      (float-array n)]
    (doseq [i (range n)]
      (aset x i (.nextFloat random)))

(seq  (rnd-f-arr 2))

^-- help shortening the above: I think it can be made more idiomatic


hmm, I get:

(defn rnd-f-arr [n] 
  (let [random (java.util.Random.)]
    (float-array n (repeatedly n #(.nextFloat random)))))
is this still as efficient, or does 'repeatedly' cause performance problems


(aset (float-array [0 0 0 0]) 2 2) <-- what am I doing wrong in this code? I'm passing it an array, an index, and a number


2 is not a float


(or a double)


yeah, changing it to 2.0 made it work


is there a way to "unquote" format strings? for macros, we can do

`( .... ~(...))
now, for format strings, we can do (format "v: %s, i: %s" v i) ... but is there a way to "unquote" where the v/i are placed right at the %s ?


(ns a.behemoth
  (:import [jcuda.jcublas.JCublas]
  (:require [a.atlantis :as a]))

is there a way I can shorter the jcuda.jcublas.JCublas/cublasInit


(ns a.behemoth
  (:import (jcuda.jcublas JCublas)))



ah, that works; thanks!


so 'classes' can be imported as 'namespace' ?


That's how we've always done our Java interop imports. The ( vs [ is just a weird Clojure convention IIRC, imports normally use ( but requires are [. It's the space instead of dot that makes it work. I couldn't tell you why it works though


in clojure.spec, do you guys have any idea of how i could deref a value before checking it?

(s/fdef foo!
  :args (s/cat :arg1 (s/coll-of (fn [v] (instance? Bar v)))))
arg1 in foo! is a reference value containing a collection, i'd like to deref it so that i can check it with coll-of

Alex Miller (Clojure team)13:12:07

You could use s/and an s/conformer that calls deref

Alex Miller (Clojure team)13:12:10

Although i find it’s usually best to stop passing atoms around as much as possible and instead write your function on the data inside

Alex Miller (Clojure team)13:12:09

To get [email protected] point where all the logic that is worth testing operates on data, not state. Then you don’t need to spec the stateful functions


oh nice, i will try that! thanks alex! by the way, it's an exercise in which i'm simulating database collections as references, so whenever i need to query the data i use this reference + core.logic. i thought it was a good idea at the time

Alex Miller (Clojure team)13:12:57

Which is a little dicey


hello everyone I’m trying to generate a fat jar (leiningen) of a project which will run some jobs and die, and I have some module levels declarations with def that accesses the database, something like (def sms-body (get-msg-from-db "smsInviteText")) but when I run lein uberjar it tries run those commands upon compilation, is there a way to avoid that?

Alex Miller (Clojure team)13:12:40

Yeah, don’t do that :)


how? id like to have this value as a constant visible to all functions of the module

Alex Miller (Clojure team)13:12:07

Make that a function, invoke it at runtime, and pass it around

Alex Miller (Clojure team)13:12:43

I know that sounds like a pain in the ass, but you will probably be thankful a year from now

Alex Miller (Clojure team)13:12:20

The short term fix would be to wrap it in delay and then deref it where it’s used


I mean, you could have a function you invoke at startup that puts the result in a def'd atom, then just access the atom whenever you need the value, but that's a very un-Clojureish way to do it


I ll just pass it around i guess 🙂 thx


Hello, question about pedestal : is it possible to have :constraints and :path-params for static routes, i.e. routes that don't have any placeholder like :id etc. ?


FWIW there is a #pedestal room which be a better place to ask


oh thanks, didn't know


My use case is that I'd like to pre-generate all routes of my app (several millions, I think 2~5) since I know them in advance, but still be able to differentiate them in the interceptors. Some are product pages, others are listing pages. Several of them will also have query-params attached to them (like ?productid=X)


Or maybe I need to do something else once I generate the routes ? I can't find enough help in pedestal docs/tests/source as to what to pass to expand-routes (to be more precise, to some function that will call expand-routes).


Hey folks, I'm trying to get gen-class working and I can't seem to get the syntax right for passing an array of Strings. I've tried the following (and then some). I'm sure the actual answer is pretty simple, but I haven't found it yet. Can someone help me out? Thanks!

  :methods [#^{:static true} [foo [[Ljava.lang.String;] int]])

  :methods [#^{:static true} [foo [#^"[Ljava.lang.String;"] int]])

;Another guess
  :methods [#^{:static true} [foo [(Class/forName "[Ljava.lang.String;")] int]])


Anyone know a good python slack team? or anyone here know python?


I can help with Python


@markbastian Corrected:

;!topic/clojure/TFLUw8GSAbY corrected
 ;; Remove spurious hash-and-caret (#^) in front of type definition
  :methods [#^{:static true} [foo ["[Ljava.lang.String;"] int]])
Now, incidentally, I haven’t been able to get a static definition to work…


you can replace #^{:static true} with ^:static iirc


True, but let’s try one more time (@markbastian)

(ns sandbox.HelpOut
   :name sandbox.HelpOutClass4
   :main false
   :methods [
             ^:static [foo ["[Ljava.lang.String;"] int]
             [bar ["[Ljava.lang.String;"] int]

(defn -foo
  "This is declared `static`"
  (let [how-many (count some-strings)]
    (doseq [[i x] (map-indexed #(vector %1 %2) some-strings)]
      (println (format "(%d): %s" i x)))

(defn -bar
  "This is an instance method"
  [_ some-strings]
  (let [how-many (count some-strings)]
    (doseq [[i x] (map-indexed #(vector %1 %2) some-strings)]
      (println (format "(%d): %s" i x)))
The ^:static notation goes before the whole vector that describes the method


also #^ is old deprecated syntax, just ^ will do


Why was it deprecated? I quite like how special things use #


because ^ is shorter


originally #^ was what ^ is now


and ^ was reader syntax for (meta


it was later changed so that ^ is syntax for with-meta like #^, with ^ being the preferred syntax


That seems different to other of clojure's design choices, especially the recent ##NaN


they're completely different scenarios


Using # for all special syntax seems consistent. Having ^ be an exception seems inconsistent.


I'm sure you wouldn't like to write #@ either


there's a number of reader macros that are not routed through the # dispatch


the reason why we went for ##NaN and not NaN is that Rich didn't want to pollute the namespace of special symbols


but in this case ^ was already reserved as a reader macro


we use # as a dispatch macro mostly just because (good) top level symbols were running out


That's true, I hadn't considered @. I'd be happy to move to #@ though. I think I've grown fond of consistent syntax.


what about :, ` ' ; ~ etc


there's tonnes of top level reader macros


and there's absolutely no reason for them to be prefixed


There's much less sanctity of # than I realised when making the comment. I think I've seen comments valuing that clojure has concise syntax for many things, it makes sense in that context.


I still struggle to picture myself wanting #^ to be shorter.


you've never used ^foo or ^:foo then I assume? ;)


here's the thing, #^ didn't become ^ because it was shorter, rather, we realized that ^ as a reader macro for (meta had virtually no use, while with-meta had quite a bit of use


so it was decided to repurpose ^ to be the more useful with-meta, and #^ was kept for backwards compatibility


I see, that's a more interesting growth. I can't actually see a particular purpose for the old ^ symbol. I have never used those much, no. They don't seem to come up in normal use of clojure, for me. Not enough that I'd want to shave a character off. Generally speaking, outside of functions and arguments, I don't see any use of metadata in clojure code. Arguments cited usually involve losing metadata under certain cases, and being concealed.


Awesome, thanks for the help!


I was glad for the (re-?)education, thanks for the opportunity


(And, as for “old deprecated syntax”: some learn from older books, like those in former Colonies learning English from books from the 1880s; some of us are old enough [in Clojure] that that syntax was once our native tongue, and we have to learn your newfangled slang.)


I believe ^ has been the preferred way since 1.2, so for quite a long time :)


This has been my fallback link every time I forget how to do this and it has "Ye Olde English" style. Perhaps an updated example on would set things aright.


@markbastian An alternative to generating classes in Clojure is to use the Java API to require and invoke code (it's the approach we've used at World Singles) -- see Alex Miller's answer to that SO question


could someone please advice? I want to load namespace every time I run "lein repl", but not on other tasks...

Drew Verlee20:12:46

Are there any clojure SQL libs that just make every table lazily available? Something like (take 2 (:customers tables)) => [{:name "drew"} {:name "sally"}]


@faxa one traditional answer to this is to add :profiles {:dev {:source-paths ["dev/"]}}, and then put the code you want to load in dev/user.clj where Clojure will load it automatically for you.


@aardem , but won't dev/user.clj load on all other tasks as well?


I wish there were special profile for repl...


@drewverlee I can think of all sorts of ways that would be problematic for resource usage (connections etc). Also, what would it mean to lazily process a table while updates were made to that table in other threads or processes?


About the closest you can probably get is building some sort of abstraction on top of reducible-query (from because you could use sequence and/or eduction to produce sequences of rows from tables... (off the top of my head).

Drew Verlee20:12:15

Good input @seancofield thanks. hmmm


that's mess for a beginner... I am trying to extend the :repl profile ` :dev-repl {:repl {:source-paths ["src" "env/dev"] :main "env.figwheel-api"}}` but fails with Warning: no nREPL dependency detected.


;; (wrap cublasSasum 3) -> #(JCublas/cublasSasum %1 %2 %3)
;; (wrap cublasSaxpy 4) -> #(JCublas/cublasSaxpy %1 %2 %3 %4)

(defmacro wrap [fname n]
  (let [args (vec (take n gensym))
        jname ...]
    `(fn ~args
       (~jname [email protected]))))
what do I put in the ... ? JCublas = not a clojure namespace, but a Java class


(symbol "" (name fname))


Is it possible to launch REPL with different Leiningen profile? Is it only my setup? :face_with_rolling_eyes:


two options: lein with-profile +foo repl - that merges the foo profile in; lein with-profile foo run -m clojure.main ... that starts a vanilla repl with only the foo profile (no nrepl btw)


thank you very much!


Can I run lein repl with different user.clj specified? ideally cpecified via Leiningen's profile.clj...


wouldn’t putting a different directory on the front of the classpath (source-paths) so that the user.clj there is found first do the trick?