This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-19
Channels
- # adventofcode (82)
- # beginners (70)
- # boot (34)
- # boot-dev (13)
- # cider (45)
- # clara (4)
- # cljs-dev (3)
- # cljsrn (2)
- # clojure (91)
- # clojure-art (8)
- # clojure-czech (1)
- # clojure-dusseldorf (3)
- # clojure-france (11)
- # clojure-germany (1)
- # clojure-greece (39)
- # clojure-hamburg (1)
- # clojure-italy (24)
- # clojure-norway (2)
- # clojure-spec (7)
- # clojure-uk (31)
- # clojurescript (56)
- # core-async (7)
- # cursive (8)
- # data-science (10)
- # datomic (41)
- # duct (7)
- # emacs (1)
- # events (1)
- # fulcro (83)
- # graphql (6)
- # klipse (1)
- # leiningen (28)
- # lumo (67)
- # off-topic (14)
- # om (9)
- # onyx (3)
- # perun (4)
- # re-frame (22)
- # reagent (11)
- # ring-swagger (2)
- # rum (1)
- # specter (46)
- # sql (13)
- # uncomplicate (17)
- # unrepl (114)
@qqq Clojurescript projects and tools like https://github.com/anmonteiro/lumo 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?(defn rnd-f-arr [n]
(let [random (java.util.Random.)
x (float-array n)]
(doseq [i (range n)]
(aset x i (.nextFloat random)))
x))
(seq (rnd-f-arr 2))
^-- help shortening the above: I think it can be made more idiomatichmm, 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
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]
[jcuda])
(:require [a.atlantis :as a]))
(jcuda.jcublas.JCublas/cublasInit)
is there a way I can shorter the jcuda.jcublas.JCublas/cublasInit
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
You could use s/and an s/conformer that calls deref
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
To get to@the 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
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?
Yeah, don’t do that :)
Make that a function, invoke it at runtime, and pass it around
I know that sounds like a pain in the ass, but you will probably be thankful a year from now
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
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
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!
;Nope
(:gen-class
:methods [#^{:static true} [foo [[Ljava.lang.String;] int]])
;https://groups.google.com/forum/#!topic/clojure/TFLUw8GSAbY
(:gen-class
:methods [#^{:static true} [foo [#^"[Ljava.lang.String;"] int]])
;Another guess
(:gen-class
:methods [#^{:static true} [foo [(Class/forName "[Ljava.lang.String;")] int]])
Anyone know a good python slack team? or anyone here know python?
@markbastian Corrected:
;https://groups.google.com/forum/#!topic/clojure/TFLUw8GSAbY corrected
(:gen-class
;; 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
(:gen-class
:name sandbox.HelpOutClass4
:main false
:methods [
^:static [foo ["[Ljava.lang.String;"] int]
[bar ["[Ljava.lang.String;"] int]
]))
(defn -foo
"This is declared `static`"
[some-strings]
(let [how-many (count some-strings)]
(doseq [[i x] (map-indexed #(vector %1 %2) some-strings)]
(println (format "(%d): %s" i x)))
how-many))
(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)))
how-many))
The ^:static
notation goes before the whole vector that describes the methodit 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
Using # for all special syntax seems consistent. Having ^ be an exception seems inconsistent.
the reason why we went for ##NaN
and not NaN
is that Rich didn't want to pollute the namespace of special symbols
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.
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.
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!
(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.)
This has been my fallback link every time I forget how to do this https://stackoverflow.com/questions/2181774/calling-clojure-from-java and it has "Ye Olde English" style. Perhaps an updated example on https://clojure.org/reference/java_interop 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 https://stackoverflow.com/questions/2181774/calling-clojure-from-java/23555959#23555959
could someone please advice? I want to load namespace every time I run "lein repl", but not on other tasks...
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.
Special profile for :repl
? I think there is: https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md
@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 clojure.java.jdbc
) because you could use sequence
and/or eduction
to produce sequences of rows from tables... (off the top of my head).
Good input @seancofield thanks. hmmm
Special profile for :repl
? I think there is: https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md
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 ~@args))))
what do I put in the ... ? JCublas = not a clojure namespace, but a Java classIs 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)
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?