Fork me on GitHub
#clojure
<
2018-06-24
>
valerauko07:06:48

I'm using case with keywords, but lein check tells me that's probably not good: >Performance warning, project/file.clj:69:7 - case has int tests, but tested expression is not primitive. The code's like

(case (:key-to-check my-map)
  :a (do-a)
  :b (do-b))
Is there a way to resolve the warning or should I just ignore it? (It bugs me)

hiredman07:06:28

that case doesn't match the warning

hiredman07:06:00

I would expect something like (case (:foo m) 1 :a 2 :b)

hiredman07:06:39

also, with a quick search of the lein code, it doesn't look like "Performance warning" is something lein check does, so my guess is you have some plugin that is adding that, and that plugin might be junk

valerauko07:06:03

I don't have any plugins added this project

hiredman07:06:20

sorry, no it is a thing in the clojure compiler I hadn't come across

valerauko07:06:55

you're right though, it was a different case

hiredman07:06:09

user=> (set! *warn-on-reflection* true)
true
user=> (fn [] (case (:foo 1) :a nil :b nil))
#object[user$eval147$fn__148 0x64ba3208 "user$eval147$fn__148@64ba3208"]
user=> (fn [] (case (:foo 1) 1 nil 2 nil))
Performance warning, NO_SOURCE_PATH:3:8 - case has int tests, but tested expression is not primitive.
#object[user$eval152$fn__153 0x71cf1b07 "user$eval152$fn__153@71cf1b07"]
user=> (fn [] (case (int (:foo 1)) 1 nil 2 nil))
#object[user$eval157$fn__158 0x3300f4fd "user$eval157$fn__158@3300f4fd"]
user=> 

valerauko07:06:59

it was a case like this

(case status
  200 (ok)
  404 (not-found)
  (internal-server-error))

valerauko07:06:16

the else clause was causing the warning

hiredman07:06:03

seems unlikely, are you sure it isn't because the compiler can't tell that status is an int?

valerauko07:06:15

status is extracted from a response map -- how would i type hint that?

hiredman08:06:00

(case (int status) ....)

πŸ‘ 4
πŸ’― 4
valerauko08:06:27

yup that resolved it

valerauko08:06:06

it's amusing because if i just use an (if (= status 200)) it says nothing

hiredman08:06:14

case is often used for performance sensitive stuff, and has a fast path for certain kinds of things like if the text expression and all the cases are ints

hiredman08:06:57

case does constant time dispatch, and is not the same thing thing has if

dottedmag08:06:42

Is there any no-configuration local database a-la Datomic? Ideally featuring the same API.

dottedmag08:06:34

I think I can make something out of Datascript, but if someone already has done that then it'd be a waste of time.

dottedmag08:06:26

@rakyi Thanks! I was trying to recall this name.

jrychter09:06:49

@alexmiller Thanks, but I think I have a pretty good use case for actually doing that (unless by "that" you mean AOT). I am digging through JIRA tickets, but can't find one related to this issue. Should I open one?

Alex Miller (Clojure team)13:06:46

I know I worked on this same problem for someone at Cognitect last year but I think ultimately it was easier to just restructure the code

Alex Miller (Clojure team)13:06:17

I know the init methods are chunked up per 100 vars but there is someplace else in the init that it comes up

jrychter13:06:06

Ok, I'll make a note to open an issue for this.

jrychter13:06:10

And yes, I did work around it β€” by splitting the namespace (by FontAwesome icon "style", the reason I needed so many defs is because these namespaces are auto-generated from FontAwesome's icons.json). This should buy me some time until the library grows so much that I'll exceed the 3274 forms limit. So it isn't a complete showstopper, just an annoyance.

sova-soars-the-sora14:06:45

Hi everyone, I just released a very experimental message board, it's a web server written entirely in Clojure, check it out: http://practicalhuman.org

8
sova-soars-the-sora17:06:54

P.S. there are no images on the message board yet, so don't worry about getting into something vulgar, it's just text right now! haha. Some jokesters making funny board names.