Fork me on GitHub
#clojure
<
2018-12-27
>
flyboarder00:12:20

Anyone else running into this issue on 1.10? No matching field found: exists for class java.io.File

flyboarder00:12:51

(defn- load-properties [file]
  (when (.exists file)
    (with-open [r (io/reader file)]
      (doto (Properties.)
        (.load r)))))

seancorfield00:12:13

@flyboarder What version of Java are you running on? That sounds more like a Java reflection/lookup issue to me.

flyboarder00:12:41

im using graalvm compiles to native image fine but getting this at runtime

seancorfield00:12:22

We use .exists on java.io.File objects all over the place on OpenJDK 8 / Clojure 1.10 with no problem -- so that suggests a GraalVM issue perhaps?

seancorfield00:12:18

I wonder if adding a type hint on file would solve that? (defn- load-properties [^java.io.File file] …

eraserhd00:12:08

@flyboarder Graal can’t find things by reflection unless you configure it to do so with a separate JSON file. This is how Clojure calls Java interop methods when it doesn’t know the type.

eraserhd00:12:12

The type hint will fix it. But you should turn on reflection warnings in your project.clj to avoid further surprises.

flyboarder01:12:19

@seancorfield @eraserhd the type hint didn’t work - i’ll try with (set! *warn-on-reflection* true) and see what happens

flyboarder01:12:24

@seancorfield @eraserhd thanks everyone! The reflection warnings allowed me to add all the required type-hints

flyboarder01:12:34

native image is crazy fast!

victorb01:12:49

startup is crazy fast. Seems to be some worries about overall performance being slightly slower as of now, but if you only need better startup, it is indeed crazy fast!

flyboarder23:12:54

performance being slower only seems to be a thing when running the SubstrateVM, JVM performance is normal

flyboarder01:12:38

real	0m0.584s
user	0m0.010s
sys	 0m0.010s

😮 12
abdullahibra12:12:48

why i couldnt use ~x# in this macro ?

abdullahibra12:12:16

i would like to eval what x# has as local variable

abdullahibra12:12:57

what i try to do is: i want to iterate over expressions, and the values with X type will do some process with it else skip

manutter5112:12:36

You don’t need the ~ there, because it’s a symbol generated by the macro itself. The ~ is just for “unwrapping” symbols you pass into the macro when you call the macro.

manutter5112:12:23

So you need it for s but not for x#

abdullahibra12:12:42

but i want to process the value of the var not the var itself

manutter5112:12:30

Yeah, that’s the tricky part of macros, they execute before vars have values.

manutter5112:12:05

But maybe you mean something different than what I think you mean?

abdullahibra12:12:27

i want to get the actual class of the variable r1 and r2 for example

abdullahibra12:12:37

(def r1 1), (def r2 2)

abdullahibra12:12:17

so i should get [jclojure.lang.Symbol ava.lang.Long java.lang.Long]

manutter5112:12:19

Try (macroexpand-1 (iter-exp 1)) and see what the result looks like.

manutter5112:12:28

Ok, I think I’m starting to follow a little better what you’re trying to do here (still sipping my morning coffee, trying to get the brain cells working)

manutter5112:12:03

Macros in the morning are a heck of a way to start the day! 😉

4
manutter5112:12:00

Ok, so what you’re seeing is the classic “macro-compile-time” versus “evaluation-time” problem.

manutter5112:12:40

Oh wait, I missed something

manutter5112:12:52

Left off the quote

manutter5112:12:30

Try this: (macroexpand-1 '(iter-exp '(+ r1 r2)))

manutter5112:12:00

That should give you the intermediate step of what your macro actually “compiles” to at “macro-compile-time”.

manutter5112:12:33

Also, maybe you don’t even want a macro here?

(def r1 1)
=> #'user/r1
(def r2 2)
=> #'user/r2
(mapv #(class (eval %)) '(+ r1 r2))
=> [clojure.core$_PLUS_ java.lang.Long java.lang.Long]

manutter5112:12:55

The First Law of Macros is: “Don’t use macros” 🙂

😄 4
😂 4
💯 4
emccue15:12:13

The second law of macros is that an object with constant velocity will maintain that velocity unless acted upon by a net unbalanced force

dpsutton15:12:14

unbalanced is redundant here correct?

emccue18:12:09

No, unbalanced is important. The phrase people usually use for the law "acted upon by an outside force" is wrong because it leaves that out

dpsutton19:12:40

What is the difference between net force and unbalanced force then?

pasi17:12:26

hm not sure if this is the right place to ask, but can I get buddy's token auth backend to recognise that my token is in a cookie (rather than header)?

cjsauer17:12:27

@pasi it looks like you'll want to implement a custom backend, extending the buddy.auth.protocols/IAuthentication protocol's parse method with your own cookie parsing code. Your implementation could very well defer to an existing backend for the rest of the protocol's methods too, so you wouldn't have to implement the entire protocol. https://github.com/funcool/buddy-auth/blob/master/src/buddy/auth/backends/token.clj#L85-L87

pasi18:12:27

hm yeah; I guess that looks simple enough. I might just go with an auth header initially to keep things simple tho

dangercoder19:12:33

I am batching data, in real time using core-async, a game queue (with different predicates like, maps, server-country). I've solved it by creating 1 core async channel per combination and attaching a go-loop with some functions that takes care of Cancel, New Player etc... Anyone with a tip on how I can do this in a better way? I currently have 300 core-async channels because I have quite a few possible combinations. I was thinking of using Kafka and something like Onyx to do "batching by predicates", this has to be quick (in real time since its a game queue).

dangercoder19:12:38

Would also appreciate some links to where I can find more useful information how to build stuff like this.

yonatanel20:12:10

How do you map from predicates to a channel?

dangercoder20:12:56

I have a pre-defined lookup, so If a player queues up I will find the correct channels to put them on. The channels and the processors (go-loops for each channel) is defined on startup.

dangercoder20:12:28

Also when a go-loop ("processor") have batched enough players, it will send a "remove me" message to all the other channels a player is on.

rutledgepaulv03:12:33

What problems do you have with your current approach? channels are pretty cheap afaik

lvh20:12:45

How do I define a static method with deftype? Do I have to port this code to gen-class?

didibus20:12:31

Yea, you do.

didibus20:12:01

As far as I know, deftype can't generate static methods

andy.fingerhut21:12:58

Well, alternately you can define it in Java, in case that helps you more easily tweak any/all Java class-creation knobs that exist.

Jacob Haag21:12:52

I am unsure why I am getting this message after running lein uberjar in my project

Release versions may not depend upon snapshots.
Freeze snapshots to dated versions or set the LEIN_SNAPSHOTS_IN_RELEASE environment variable to override.
I changed the version in my project.clj to not include -SNAPSHOT and I get this message. Would anybody be able to provide me with context to this message and maybe how to resolve it? (besides slapping -SNAPSHOT back onto the end of the version)

manutter5121:12:01

I think it's complaining about one of the dependencies in your project.clj having a -SNAPSHOT version.

Jacob Haag21:12:03

@manutter51 there are no dependencies with the extension -SNAPSHOT. I created a project with bare bone project with lein new __ and removed snapshot and ran lein uberjar and got the same message.

Jacob Haag21:12:51

Figured it out, for some reason lein uberjar is trying to include dependencies defined in my profiles.clj and inject them into the uberjar.

manutter5121:12:03

Aha, that was going to be one of my next suggestions. Seems like profiles.clj has been cropping up a lot recently.

dpsutton21:12:46

> for some reason that is by design. those are global dependencies

Jacob Haag21:12:25

That makes sense, does that include all the profiles in your profiles.clj? (ex. :user and :repl)

dpsutton22:12:56

no profiles is how you mix and match them. I think these problems pop up enough to confirm that they aren't good ideas and they cause problems often. Just put the dependencies that you want into your projects individually