Fork me on GitHub
#clojure
<
2017-10-09
>
qqq06:10:38

there's clojure library FooBar, which uses JNI. There's two JNI options. CPU support and GPU support. Maven package of FooBar has CPU support. I built a local *.so with GPU support. How do I properly package up FooBar so that my local boot config picks up my LOCAL *.jar with the GPU support ?

qqq06:10:12

I expect this to be a mess, so if you can point me at some docs / tutorials, I can go hash it out myself.

martinskou11:10:57

Emacs related question, but is there any way go get a list of definitions/functions in the current buffer or project?

chrisblom12:10:47

for the current buffer i use M-x imenu

chrisblom12:10:32

or you can use M-x helm-imenu if you have helm

martinskou12:10:47

Thanks, works like a charm, found imenu-list emacs plugin as well.

hlolli13:10:56

sensible testers, how do you access the test result from clojure.test after a test run via lein test, what I'm looking to do is send email/slackmsg after all tests.

hlolli13:10:24

I use use-fixture to correctly sequence the test, didn't try, but maybe it returns what I'm looking for...

huwigs14:10:28

is there an idiomatic way to write a function that will read a string per edn/read-string, but return values that get returned as symbols to be returned as strings instead?

huwigs14:10:09

i.e. read-string looks like (read-string "42") -> 42, (read-string "hello") -> hello

huwigs14:10:41

I would prefer (read-string "42") -> 42, (read-string "hello") -> "hello"

hlolli14:10:52

(read-string "\"hello\"") ?

huwigs14:10:04

the actual strings are being read in from a CSV file

huwigs14:10:15

a CSV without quotes 😛

huwigs14:10:20

tab-separated, actually

huwigs14:10:38

so I can’t really control the input to read-string very well, or I’d prefer not to

hlolli14:10:07

hmm, pass the symbol 'hello to the function name?

huwigs14:10:49

read-string is probably not actually what i want, looking more closely

huwigs14:10:03

I guess i have to try to parse the string as a number, and if it fails just return the string

dominicm14:10:37

@steve313 if it's number or string, then yeah, do that.

hlolli14:10:41

you can also use a function, not in clojure.core tough, numeric? if you only want to get the numbers out of the string and read them only.

huwigs14:10:55

some numbers are floats and other numbers are ints though 😞

dominicm14:10:15

@steve313 treat them all as float?

huwigs14:10:34

I think I might be able to get away with that

dominicm14:10:47

Clojure doesn't care about the differences.

huwigs14:10:48

Most of them are floats for sure

hlolli14:10:01

this one from rosetta stone works for floats I believe

(defn numeric? [s]
  (if-let [s (seq s)]
    (let [s (if (= (first s) \-) (next s) s)
          s (drop-while #(Character/isDigit %) s)
          s (if (= (first s) \.) (next s) s)
          s (drop-while #(Character/isDigit %) s)]
      (empty? s))))

huwigs14:10:29

probably easier to just catch the error from converting…

dominicm14:10:33

@steve313

user=> ((fn [n] (try (Float. n) (catch NumberFormatException _ n))) "hello")
"hello"
user=> ((fn [n] (try (Float. n) (catch NumberFormatException _ n))) "10")
10.0
user=> ((fn [n] (try (Float. n) (catch NumberFormatException _ n))) "10.5")
10.5
Does that work for you?

huwigs14:10:56

using (float n) though… is there a difference?

huwigs14:10:17

Oh, yes there is

huwigs14:10:23

that’s just a class cast exception

lhall15:10:33

is there a clojure built-in for compositing multiple boolean checks? i.e. (?? arg [is-x? is-y? is-z?]))

phill15:10:12

(map Boolean? [a b c])

ghadi15:10:36

some-fn or every-pred depending on your needs @lhall

ghadi15:10:46

they're combinators

lhall15:10:08

every-pred is what I’m looking for. Thanks!

ghadi15:10:44

beware, depending on the situation it can reduce readability

noisesmith17:10:18

also I doubt anyone would find this intuitive (though it’s probably useful in some context)

peregrine.circle=> ((every-pred even? pos?) 2 -1 1)
false
peregrine.circle=> ((every-pred even? pos?) 2 4 6)
true

ghadi17:10:57

I usually only use the combinators when I'm passing the resulting function somewhere else

Kari Marttila16:10:59

I found today a really weird behaviour with insert-multi! and Redshift jdbc driver. If I give to insert-multi! two rows like [["id1" 1.1] ["id2" 2.2]], I get values 1.1 and 2.2 in Redshift. But if I give rows [["id1" 1] ["id2" 2.2]] then I get values 1 and 2 (not 1 and 2.2) in Redshift. I was wondering that this should probably not be the default behaviour (the first row is used to interpret the type of columns or something weird like that)?

dpsutton16:10:12

can you run into the 20 arg limit of function calls with apply? I'm a little confused why (apply str (take 100 (range))) works, as i assume this is calling str on 100 args

noisesmith16:10:07

there’s no such limit, after 20 args it takes a varargs

noisesmith16:10:09

this is the highest arity defined, notice it ends with Object… at the end https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java#L89

bronsa16:10:26

the limit is on function definition not function invocation

bronsa16:10:37

you can't define a function with more than 20 fixed args

bronsa16:10:46

but you can use varargs

bronsa16:10:16

i.e. rather than (defn foo [a1 .. a21 a22]) you can do (defn foo [a1 .. & [a21 a22]])

dpsutton16:10:34

ok. that's always been fuzzy in my head. thanks for clearing that up for me

kaosko17:10:40

hey anybody using re-frame? if so, do you know if it's usable on JVM yet?

kaosko17:10:10

at least the basics seems to work. the tests are not yet converted to .cljc so there could be dragons

danielcompton18:10:27

@kaosko re-frame on JVM is only intended for testing/development, not production use

danielcompton18:10:08

At least at the moment, we haven’t had people want to use it in prod (not sure what the use case is)

danielcompton18:10:40

But people do use it. re-frame-test allows you to write cross platform tests too

kaosko18:10:50

thanks @danielcompton. I'm happily using re-frame on the client but I'm seeing a use case for it on the server as I have to keep a fairly complex load state tree in memory per user. I'm trying it right now!

danielcompton19:10:19

ok, good luck, let us know how it goes, and feel free to open issues about it on re-frame. It's not a core use for us, but happy to take PRs on it. The architectural pattern for "re-frame on the server" is CQRS, so take a look for other CQRS systems for more inspiration

kaosko19:10:14

thanks, sounds good. it's a shot in the dark, but at this point I felt the alternative would have been a plain global atom, so might just as well try re-frame here

andrea.crotti21:10:59

I'm trying to add some server side rendering to a pedestal+reframe project

andrea.crotti21:10:08

so I just added clostache and in theory it should be quite simple

andrea.crotti21:10:28

I just changed it from

(defn home-page
  [request]
  (-> (ring-resp/file-response "index.html" {:root "resources/public"})
      (ring-resp/content-type "text/html")))
to
(defn- get-config
  [language]
  (merge
    ENV
    {:language (str language)}
    (get TEXT language)))


(defn render-homepage
  [language]
  (clostache/render-resource
   "public/index.moustache"
   (get-config language)))

(defn home-page
  [request]
  (-> (ring-resp/response (render-homepage :en) {:root "resources/public"})
      (ring-resp/content-type "text/html")))

andrea.crotti21:10:53

but with the second version Figwheel keeps on complaining that it doesn't find the resource

andrea.crotti21:10:09

even though playing around in the REPL it seems all correct

andrea.crotti21:10:13

any idea about what it could be the problem?

didibus23:10:41

Any way I can with-redef clojure.tools.logging log/warn ?

bfabry23:10:11

@didibus redef clojure.tools.logging/logp

bfabry23:10:31

sorry, log*

bfabry23:10:02

clojure.tools.logging/log* is the function that all those macros eventually delegate to

didibus23:10:18

Ah, ya that works

didibus23:10:22

So can you not redef a macro?

didibus23:10:53

I thought it would still just be pointed by the var, and so would have its macro be replaced

didibus23:10:15

Oh, I guess its expended at load time, so before with-redefs runs?

bfabry23:10:53

guess so, I never really thought about it too hard

didibus23:10:44

alright, thx