This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-23
Channels
- # ai (1)
- # beginners (84)
- # boot (111)
- # cider (2)
- # cljsrn (9)
- # clojure (245)
- # clojure-italy (2)
- # clojure-mke (1)
- # clojure-russia (6)
- # clojure-spec (92)
- # clojure-uk (32)
- # clojurescript (55)
- # core-async (1)
- # cursive (8)
- # datomic (19)
- # events (1)
- # hoplon (379)
- # lambdaisland (4)
- # lein-figwheel (8)
- # off-topic (115)
- # om (18)
- # om-next (5)
- # onyx (25)
- # re-frame (8)
- # reagent (5)
- # ring-swagger (1)
- # rum (19)
- # schema (3)
- # untangled (24)
(let [form '((nil? x) a b)
[g if-t if-f] form]
`(let [ret# ~g]
(if (boolean? ret#)
(if ret#
~if-t
~if-f)
(ret# ~if-t ~if-f))))
i feel like it's ok to assume 'faulty' premises if you work inside, like how you are given params in a spec/function and work inside it
questions should mention if something is for production or just for YOLO purposes
so maybe you can replace the premise with something more applicable later of similar spec
i have a folder full of random YOLO code. last year i wrote a clojure to ruby compiler in ruby. i called it “risk”. 😄
so @noprompt seems like the macro needs to be like (the-macro (... all ur code here ...))
Hi everyone... I have a web application backend that makes use of java code, which I added from an external repository (not from Clojars). My backend works well when I start it through lein repl
or lein run
, however, it doesn't work from an uberjar. It fails on starting a component which use the java code I mentioned before. Shouldn't be the context/environment of those types of execution equal?, could be a difference between the java class path on them?
you can debug the classpath using lein classpath
yeah, anything of that sort
lein classpath
helps you run the code without leiningen being involved, which eliminates a lot of possibilities
how does it fail, exactly?
First, I get some warning messages. Like this: WARNING: Required dependency 'org.pentaho.reporting.engine.classic.core.ClassicEngineCoreModule' for module 'org.pentaho.reporting.engine.classic.core.modules.gui.common.GuiCommonModule not initializable.
I know, I'm saying you can call java
yourself using the output of lein classpath
that way you have a raw java
command that may or may not have the same problem
SEVERE: class org.pentaho.reporting.engine.classic.core.ClassicEngineBoot failed to boot: java.lang.IllegalStateException: Booting the report-engine failed.
@gfredericks ok, I understood
rcanepa
you could call java
with the clojure.main
class if you want and it would start a repl
wow I did the @ completely wrong there
@gfredericks if I understood you well, I should start my application using java (without leiningen) and see what happens, right?
I used java with clojure.main and the classpath provided by lein classpath
. I started the application and it didn't throw any error.
smells like leiningen is the problem
probably the next step is figure out exactly what java
command leiningen is running when you do lein run
I'm not quite sure how to convince leiningen to tell you that but maybe somebody else knows
ps aux | grep java? ... it shows /usr/bin/java -classpath <insert huge class path here> <insert java variables> clojure.main -i /private/var/folders/nf/gvk9h4953097hspqvpdrrh300000gn/T/form-init5259320840110875260.clj
I printed the java.class.path from the uberjar and I got one reference to the .jar file.
all the stuff in the /private/...clj
file can be important
likely difficult to read though; depends on how motivated you are
oh another thing to try is LEIN_NO_USER_PROFILES=1 lein run
if you have a user profile
and/or deleting any extraneous libraries/plugins from your project.clj
Ok... I will try that too. Also, the only library or piece of code which is giving me troubles are these java classes from an external repo. In order to add those dependencies I had to add this keyword :repositories [["pentaho" "
to my project.clj
Is there a way to convert an Exception to a stringy format (in order to be passed as message over the wire) and keep the stacktrace info as well?
@richiardiandrea having the same problem myself. if you generate exceptions with ex-info
and consume them with ex-data
, they are more easily serializable. unfortunately doesn’t help for java exceptions/errors. if you find anything that solves your problem would love to hear it
@mss there is print-stacktrace
in https://clojure.github.io/clojure/clojure.stacktrace-api.html
Yeah I am trying those now 😀
Oh cool!
Thanks @mss
How do I define a schema where I have non-empty vector of type? If I do
[(s/one s/Str)]
, it only allows one, but I’d like to have one or more, like + in regular expression?
(cross posting from #schema)Hmh, I remember getting class cast exception, maybe there was some other error with it...
@igrishaev Thanks, I don’t know what I did wrong when I tried that last.
Ah, yeah, I think it’s because my type is an enum and causes a bug somewhere else enum schema.core.EnumSchema cannot be cast to clojure.lang.Named
what is the best way to generate that output
input: “olivia”
output ( “o” “ol” “oli” “oliv” “olivi” “olivia”)
I’m trying to use partition / partition-by but not getting correct output 😞
Is clojure.java.browse always loaded? I just the-ns
‘d it, and I was expecting that to fail.
I am writing a test for a fn that is like the-ns, except it will require the ns first, so that it always succeeds.
payne.core-test> (the-ns 'clojure.java.browse)
java.lang.Exception: No namespace: clojure.java.browse found
payne.core-test> (require 'clojure.java.browse)
nil
payne.core-test> (the-ns 'clojure.java.browse)
java.lang.Exception: No namespace: clojure.java.browse found
payne.core-test> (require 'clojure.java.browse :reload)
nil
payne.core-test> (the-ns 'clojure.java.browse)
java.lang.Exception: No namespace: clojure.java.browse found
clojure.java.browse
is in (loaded-libs)
— I was hoping that’s what :reload would address.
Hi All. I am trying to call clj -main
method from Java (via bazel). If I just load a clj script with RT, I get into that script's namespace. If I invoke only -main
method, however, I remain in clojure.core
namespace. Cant google much help on how to do both: switch to the clj namespace and call a method there, from java
When I attach metadata to a var like so:
^{:reason "General market metadata, not security-relevant"}
#'amazonica.aws.ec2/describe-spot-price-history
Where does the metadata go? (Clearly not on the var.)oh, this seems to work
RT.var("clojure.core", "require").invoke(Symbol.intern(main));
Var.pushThreadBindings(RT.map(RT.var("clojure.core", "*ns*"), main));
RT.var(main, "-main").applyTo(RT.seq(args));
hope, its OKhello, if i do, (drop-last [1 2 3]), it becomes a list (ie. vector? on the results returns false). how can i keep it a vector?
i have a reduce fn where i occasionally need to return a (drop-last my-accumulated-result), where my-accumulated-result is (and should stay) a vector
From: http://insideclojure.org/2015/01/07/vec-perf/ "A 1024 element vector drops from 14 microseconds to 8 nanoseconds - 1000x improvement"
Isn’t that what kah0ona is asking? they have a vec and they would like it to remain a vec
i was wondering if calling (vec ..) before returning would be a significant perf impact
because basically each iteration of the reduce i do a drop-last (which stops it being a vec), and then making it a vec again with (vec ..)
kah0ona but if you want an alternative that preserves vec-iness, subvec does what you want
kah0ona if all you do all the time is drop-last, maybe you just don’t want a vec to begin with, iunno
e.g. if you care about something being on the front or the back, conj will do the opposite on a vec vs a seq
the csv is already in chronological order (i have a csv file of electrical current peak readouts, each row is a time stamp and a power (watts) integer)
i'm trying to make some sense of it, but it's a daemon that does this for lots of potential sources that produce these csv's
grouping rows because of their order relative to one another, or based on some data in the individual rows
Have you considered making your reduction accumulator being [peaks current-peak]
instead of peaks
where the last one is a peak in progress?
(You can destructure in the reducing fn, but maybe you don’t need reduce in the end after all, although it sounds probable)
(fn [[peaks current-peak] measurement] (if part-of-peak? [peaks (conj current-peak measurement)] [(conj peaks current-peak) []]))
(defn reduce-fn
[result-vec current]
(let [previous (peek result-vec)
current-peak (abs (second current))
previous-peak (abs (peek (:peak previous)))
current-class (classify current-peak) ; we need 2nd column
previous-class (if previous
(classify previous-peak)
nil)
current-timestamp (parse-timestamp (first current))]
;if previous is nil, it's the first item, add it
(cond
(or
(nil? previous)
;not the same? we now have a new peak, build a new record to be conj'd to the result-vec vector
(not= current-class
previous-class)) (conj result-vec
(build-new-record
current
current-class
current-peak))
;same, extend the end-time of the peak
(= current-class
previous-class) (-> result-vec
(vec)
;add updated version with new timestamp
(conj (update-record
previous
current-timestamp
current-peak))))))
but I would strongly recommend keeping your peak-in-progress separate and using destructuring as I mentioned above
i can't just bucket it though, because i need to retain info about sequential ordering of peaks
but the resulting datastructure eases my processing further on, so for now i'll stick with this
to rephrase, I consider your problem to be a category error about adding incomplete data to a set that’s mostly-complete data
and the reason you have special treatment is because that last value doesn’t belong (yet)
@tankthinks nice!
thanks @luke … hope I captured the main points
I have to be honest, coming from a Java background … when you mentioned app via configuration I had flashbacks of spring xml configuration
but I think the idea of application level concepts as configuration is revolutionary
what do you use to transform data from one data data structure to another and in the way back? Just imagine two systems with products data represented in different data structure. I am looking simple small solution. I can always do it manually, but maybe somebody did something interesting.
Hi, I have a question. I'm building an app in Clojure and I want it to display a splash screen while app starts. This means, that I need it to load before Clojure.core is loaded. Thus, it should, probably, work from Java land. (start main function in Java. It shows splash screen, while Clojure main function is loading). So, what is the best way to organise it? (The easiest, of course, is to have a .sh startup script which starts SplashScreen.jar and waits for MainApp.jar to load. Thanks.
@mik starting two jars seems not amazing, I would write a java class that is the main entry point for your application, runs the splashscreen and then runs your clojure code using Clojure.var
of course clojure.core would have to be loaded for that, but clojure.core actually loads very fast
@bfabry Well, then the question at this point becomes: "Can lein build uberjar with entry point in Java"?
probably the only caveat is it will default the repl namespace to :main unless you specify something else, which will muck things up if :main is a java class. so make sure you add a :repl-options {:init-ns user} as well
you probably want to consider just doing it in clojure first though btw, just loading core is really not slow
11326-storage:link_account_exporter bfabry$ time java -jar ~/.m2/repository/org/clojure/clojure/1.9.0-alpha12/clojure-1.9.0-alpha12.jar -e "(println \"hello, world\")"
hello, world
real 0m1.367s
user 0m1.582s
there's plenty of situations out there where 1.5s is an age, but I don't think one where you're showing a splashscreen is one of them 🙂
Hi - I am experimenting with using Apache Kafka and Clojure. Was thinking of using Java's Executors and running each Kafka producer on a separate thread. I am wondering if anyone in the community has suggestions on whether this is a good approach in terms of scalability, maintainability ...
I have a project i just generated with Leiningen, and when I run “lein repl” inside it, I’m noticing that I get the user namespace as the prompt. Is there anything I need to do differently to get my project’s namespace? Is it perhaps because I have a compojure project w/ Jetty so there’s no main method I have defined?
Why are my compojure routes not matching? I tried fiddling around with the middleware, but when I browse to http://localhost:3000/documents, I just get “not found”
(defroutes app-routes
(GET "/documents" [] (get-all-documents))
(POST "/documents" {body :body} (create-new-document body))
(GET "/documents/:id" [id] (get-document id))
(PUT "/documents/:id" {id :id, body :body} (update-document id body))
(DELETE "/documents/:id" [id] (delete-document id))
(route/not-found "Not Found"))
(def app (wrap-params app-routes))
ok, so this is more of a beginner question, why does this return nil?
(defn get-all-documents [] ({:name "Test document 1" :body "Test body 1"}
{:name "Test document 2" :body "Test body 2"}))
Look here if you want to return json: https://github.com/ring-clojure/ring-json
is the ({:name "Test document 1" :body "Test body 1"} {:name "Test document 2" :body "Test body 2”})
expression creating a list of maps? but not in the valid response structure for ring?
and applies the second map to the first one. So it looks for a key in the first map that is similar to the second map
ok, so in my defroutes when I say (get-all-documents)
I’m not actually calling that function, I’m just telling it here is a function to use to pass in a request and it returns a response.
I’m following a Compojure tutorial that has me doing DB setup right away, and I figured I’d try to get it working with static values first, just to focus on the Compojure concepts first.
I am not sure if that is true for all the cases. But it is true for lists. So while (foo)
will be evaluated, '(foo)
does not
the single quote is syntax sugar for the special form quote
so '(1 2) is equivalent to (quote (1 2)), which yields the unevaluated form http://clojure.org/reference/special_forms#quote
Does anyone know of an implementation of statistical tests like a t-test that's NOT in incanter? I'm having confusing dependency clash issues (?) with incanter and I just want a t-test (or maybe another test like an f-test), either in a simpler and more recently updated library or just a bit of source code I could copy/paste. Web searches haven't found it for me yet and I'd rather not code from scratch...
@lspector when I can't find a maintained clj lib for stuff like that I reach for java. this looks pretty good https://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/stat/inference/TTest.html
Thanks @bfabry! The rub for me will be figuring out how to get that into my clojure project... as I generally live in pure clojure and don't do interop.
I assume I need something in project.clj, something in my ns declaration, and then maybe something to massage arguments and return value so that I can make a function that I give two vectors and returns a p-value...
you'll need to add the dep to your project.clj same as you did with incanter, like here https://mvnrepository.com/artifact/org.apache.commons/commons-math3/3.2 (click on leiningen tab)
then you'll need to do something like
(let [v1 [1.2 1.4]
v2 [1.6 1.7]
new-t (TTest.)]
(.t new-t (double-array v1) (double-array v2))
clojure interop with java is really great because it gives you access to tons of libraries already written in java
I realize that in principle, but not knowing my way around java it has always been a bit mysterious too, especially because I didn't previously know how to include dependencies not on clojars... but I'm working through the changes you suggested and about to test them, and this may be the dawn of a new day 🙂
leiningen should check both clojars and maven central by default, so anything on maven central (basically the whole java ecosystem) should just work
I didn't previously know how to get the thing to put in project.clj if it wasn't in clojars...
ahhh yeah well you can click on the leiningen tab to get that. it also pays to just switch between leiningen and maven and see how the xml translates to the vector
Cool. I didn't even know about http://mvnrepository.com, to say nothing of that tab. Probably obvious if you come from the Java world, but I come from the Lisp world...