Fork me on GitHub
Marcio Arakaki00:11:07

Hi! Trying to compare two dates, clj-time/interval only works when the first date comes before the second. (clj-time/minus date1 date2) throws org.joda.time.DateTime cannot be cast to org.joda.time.ReadablePeriod. Any ideas of could I do ?


joda DateTime implements Comparable


so just (compare date1 date2) will work


clj-time also has equal? after? and before? if you want to be descriptive and avoid the whole -1 0 1 thing

Marcio Arakaki00:11:29

I need to know the difference between the 2 dates


Use compare to sort them first, then use clj-time/minus?


I mean clj-time/interval, perhaps. Sorry, whichever one you said works if the two date/times are given in time order.

Marcio Arakaki00:11:06

Thats my initial idea, with interval instead of minus.


looks like the best option to me


probably using t/after?


as it's more readable than compare

Marcio Arakaki00:11:35

yeah probbably. I was hoping for cleaner option. Thanks ๐Ÿ™‚


Just a note that Joda Time (and clj-time) is essentially deprecated since Java 8, because Java Time is built-in. (I'm one of the maintainers of clj-time BTW and I encourage people not to use it)


FWIW @UQ88JCRGU I like as a wrapper around Java Time (it's one of the things we recommend folks use instead of clj-time):

seanc@DESKTOP-QU2UJ1N:/mnt/c/Users/seanc/clojure$ clj -Sdeps '{:deps { {:mvn/version "RELEASE"}}}'
Clojure 1.10.1
user=> (require '[java-time :as jt])
user=> (-> (jt/instant) (jt/minus (jt/days 10)))
#object[java.time.Instant 0x26bb92e2 "2019-10-30T00:55:34.202273Z"]
user=> (def a *1)
user=> (def b (jt/instant))
user=> (def a-b (jt/duration a b))
user=> a-b
#object[java.time.Duration 0x577bfadb "PT240H13.605787S"]
user=> (jt/as a-b :days)
user=> (jt/as a-b :hours)
user=> (jt/as a-b :seconds)

โค๏ธ 4
๐Ÿ‘ 4
Marcio Arakaki00:11:49

BTW I'm using VSCode, and it seems that is has no auto formater (auto-ident) for clojure. Does anyone knows any options to format a clojure code ?


zprint but disclaimer I have no idea how good it is. I know it doesn't deal with quoted forms well. I'd love a solid opinionated clojure autoformatter

Marcio Arakaki01:11:39

thanks, I'll will try it out ๐Ÿ™‚


Calva does auto-formatting. And a lot more. I recommend. (But, yeah I created it, so of course ๐Ÿ˜€) I can also recommend #calva-dev


Hi everyone. I am looking for some help Java interop. Does anyone know why it might be that an object that is an instantiation of a nested class might have some of its methods missing in Clojure, but not Java?


If the nested class is declared private in Java, I have not discovered how to access it from Clojure.


What steps have you tried that lead you to believe the method is missing?


If I call the method directly, I get

ojalgo-clj.matrix.primitive-matrix=> (.limits mat (int 2) (int 3))                                                                                
Execution error (IllegalArgumentException) at ojalgo-clj.matrix.primitive-matrix/eval6966 (form-init8309903648537351375.clj:1).                   
No matching method limits found taking 2 args for class org.ojalgo.matrix.PrimitiveMatrix$LogicalBuilder 
But if I wrap it in this Java function
public class PrimitiveMatrixLogicalBuilder {
  public static PrimitiveMatrix.LogicalBuilder limits(PrimitiveMatrix.LogicalBuilder m, int rowLimit, int columnLimit) {
    return(m.limits(rowLimit, columnLimit));
Then I get
ojalgo-clj.matrix.primitive-matrix=> (PrimitiveMatrixLogicalBuilder/limits mat (int 2) (int 3))                                                   
#object[org.ojalgo.matrix.PrimitiveMatrix$LogicalBuilder 0x6537bfea "org.ojalgo.matrix.PrimitiveMatrix$LogicalBuilder@6537bfea"]  


Is the inner class declared private? Or any other Java modifiers?


Its declared static.


Does the method limits have any modifiers?


Some of the methods work and others don't ๐Ÿ˜•


You could try use the Java reflection API, e.g. getDeclaredMethod, to get a reference to the method you want to call, then call (.setAccessible the-method true), then the .invoke method, to see if that helps.


That can help if they are declared private, and perhaps even if they have no modifiers at all (not sure), but I have had difficulty trying that when the inner class was declared private.


You may want to try the #clojure channel for this question, as there may be a bigger audience of knowledgeable folks following there than in this channel.


That isn't a typical Clojure beginner question ๐Ÿ™‚


@byrongibby The problem is those are variadic methods.


To call them from Clojure you must pass an array of values in the ... position.


I assume that's the problem you're having with "some" methods rather than others?


Oh, no, you have a type compatibility issue... sorry.


(hopefully, you'd already figured out the array/variadic thing?)


@seancorfield Yep. ๐Ÿ™‚ Although I struggled with that as well...


OK. Let me read those JavaDocs for a bit and see if I have any ideas. Sorry, should have read all the way back before jumping in...


@andy.fingerhut Thanks for the advice, I'll try out your suggestions. I think this package is a little weird, I also got this obscure error previously

ojalgo-clj.matrix.primitive-matrix=> (.makeEye PrimitiveMatrix/FACTORY 2 2)                                                                       
Execution error (IllegalArgumentException) at ojalgo-clj.matrix.primitive-matrix/eval6968 (form-init8309903648537351375.clj:1).                   
Can't call public method of non-public class: public org.ojalgo.matrix.BasicMatrix org.ojalgo.matrix.MatrixFactory.makeEye(int,int)  


@seancorfield No problem, help is always appreciated.


That "Can't call public method of non-public class" message looks vaguely familiar to me ... perhaps the same one I was seeing a few days ago when trying to call a method in a private inner class. In my case I had access to the Java source and could easily create a fork for my own personal use -- it was primarily testing/debugging for my application, so not an issue for me.


Yeah, I created a Java wrapper as call is permitted in Java as was suggested to me elsewhere. I am wondering if this new error is some continuation of the same issue.


as the call*


This is an interesting problem @byrongibby ๐Ÿ™‚


Haha. I'm glad it's interesting to someone, it's been hell of a frustrating to me. ๐Ÿ˜›


@byrongibby what jvm version ?


I'm off to bed, it's 4 AM in South Africa. Thanks for the help, I'll check back later today.


@ghadi OpenJDK 64-Bit Server VM 1.8.0_232-b09


The JavaDocs (which are pretty poor) are for 47.2.0 but the current version on Maven is 47.3.1. I'd tried that first and wondered if that was part of it, so I backed off to 47.2.0 and I can repro Byron's puzzling behavior. If you call methods that take no arguments, they work. So I'm wondering if it is something specific in the way Clojure is trying to find matching methods via reflection?


I'm trying it on Java 10.0.2 (for no good reason -- I guess I just haven't updated my WSL install for a while!).


I (set! *warn-on-reflection* true) and I do not get reflection warnings from (.makeZero PrimitiveMatrix/FACTORY 2 2) -- which has only one declaration (no overloads) -- but I get a reflection warning (and a failure to resolve) from (.makeEye PrimitiveMatrix/FACTORY 2 2) -- which has two declarations (one with two int args, one with a structure object). @ghadi Wondering if we should take this to #clojure-dev as it's feeling like a bug (or a least an interesting shortcoming) in Clojure interop reflection?


I found I use clj-http.client/get download image file is not complete. Here it is.


Is it possible to re-use s/fdefs if I have several functions with the same signature?


Thanks! How would I do that? The fdef includes the function name, which is used during insturmentatin. That's why I'm stuck

Alex Miller (Clojure team)20:11:46

s/fdef is just the same as s/def on an s/fspec

Alex Miller (Clojure team)20:11:55

with a symbol as the key

Alex Miller (Clojure team)20:11:00

in fact, that is literally exactly what it is:

Alex Miller (Clojure team)20:11:24

user=> (source s/fdef)
(defmacro fdef
  [fn-sym & specs]
  `(clojure.spec.alpha/def ~fn-sym (clojure.spec.alpha/fspec ~@specs)))

Alex Miller (Clojure team)20:11:36

so you can do the same thing:

Alex Miller (Clojure team)20:11:28

(s/def ::reusable-fn (s/fspec :args ... :ret ...))
(s/def fn-1 ::reusable-fn)
(s/def fn-2 ::reusable-fn)


super, thank you!


Solved, I added (with-open ...) wrapper fixed this problem.

Arto Kalishian13:11:01

Is there any reference to understand CLJC extension? I know CLJS and CLJ but I am not sure of the purpose of CLJC.

Alex Miller (Clojure team)13:11:07

The c stands for โ€œcommonโ€ and these files are intended to work on any Clojure platform (Clojure, ClojureScript, ClojureCLR)

Alex Miller (Clojure team)13:11:08

They support reader conditional expressions that are platform conditional

๐Ÿ‘ 4
Arto Kalishian13:11:15

So on a tutorial someone was explaining the #?(:cljs conditional expression to use in a CLJC file, but I wonder why is it needed if the produced compiled code will only either run on JVM or JS runtime?

Alex Miller (Clojure team)13:11:27

Because not all code is portable

Arto Kalishian13:11:07

In other words, is the use case to write front-end code and back-end code in the same source file?


Newb here, but does this announcement from MS mean that Clojurescript can target Windows via React Native too? ( Does something like this exist for Mac/Linux? I saw a couple of presentations on Youtube where people had authored React-native cross-platform mobile apps but I thought it was only limited to mobile OSs...


What is the Clojure equivalent of this Java code? BufferedReader br = new BufferedReader(socket.getInputStream()); while ((thisLine = br.readLine()) != null) { System.out.println(thisLine); } Would this be considered the Clojure equivalent? (with-open [rdr ( (.getInputStream socket))] (doseq [line (line-seq rdr)] (println line)))


@scott.archer in my opinion that is pretty much the equivalent, the clojure code is actually doing more, since it is closing the reader afterwards

๐Ÿ‘ 4

I am learning shadow-cljs and my project includes both reagent and a library depending on React through npm. I'm afraid that there is a danger that my project will be running two instances of react, but am unsure if this worry is well founded. Does anyone have experience with this? Thanks in advance


don't need to worry. shadow-cljs will only include on react version, the one from npm in fact.


awesome, does that mean I should manually install react, react-dom, etc. through npm?


thank you very much @thheller! this is an awesome tool! I really appreciate it

๐Ÿ‘ 4

hello, anybody have a question?