Fork me on GitHub
#clojure
<
2016-01-31
>
jonahbenton03:01:31

@shriphani interesting. it sounds like what you want to do is remove the entire dependency from your project.clj and instead make sure it is visible from -Djava.ext.dir. the then classloaders should both be sun/misc/Launcher$ExtClassLoader

paulspencerwilliams12:01:16

Hi all. Can anyone suggest the following code results in a Assert failed: Args to tuple must be generators exception? https://gist.github.com/paulspencerwilliams/8d2f97f92278e8b2c61c

immo12:01:58

@paulspencerwilliams: prop/for-all expects bindings to be generators, gen/sample returns sequence of values

paulspencerwilliams12:01:46

@immoh: just picked up on it - I needed to lose gen/sample and it works. Well. It fails, but for a good reason now 😉 Thank you.

grav19:01:15

@solicode: no, you’re right, I don’t need to transpose. Your suggestion is good!

grav19:01:46

I need to get the value (not just booleans), so I’m using reduce as @jaen suggested.

grav19:01:45

(map #(reduce (fn [a b] (or b a)) :default-value vs) as bs cs …)

shriphani19:01:10

@jonahbenton: about that advice from yesterday about java.ext.dirs , how do I guarantee that the resulting jar works with lein deploy.

jonahbenton19:01:03

@shriphani: gotcha, yeah, one doesn't have that level of control with an uberjar. Capsule solves this problem: https://github.com/circlespainter/lein-capsule http://www.capsule.io/

shriphani19:01:47

@jonahbenton: is there a simple example? The minimal config doesn’t seem too descriptive

jonahbenton20:01:09

@shriphani hmm, i don't see one offhand; the basic idea is that you add the capsule plugin to your profile, and a :capsule key to your project, then you can use lein capsule to package the app. A capsule is a .jar file that includes a shim class plus your packaged app. The shim explodes your packaged app- including the JDK you want if specified- and runs it in accordance with your configuration, specified in the project.clj :capsule key, including memory settings and all the bells and whistles. The reference to the :capsule key is here: https://github.com/circlespainter/lein-capsule/blob/master/test_projects/lein-capsule-test/project.clj The :capsule options you probably care about are: * [:types :fat] - you may want to package a specific JDK with your application * [:execution :runtime :jvm-args] - specific memory settings, etc * [:paths :native-library-path] - where to find your library on the file system. This should correspond to a directory local to your project and capsule should include it at packaging time

shriphani20:01:14

I see. And when I finally do lein deploy clojars (say), it is going to just work ?

jonahbenton20:01:49

well, you will get a .jar file from capsuling, and that jar file is runnable with java -jar, but lein deploy may not know where to look for that jar file after capsuling

jonahbenton20:01:22

lein tasks expect to find artifacts in target/ and names artifacts in accordance with maven coordinates; capsule by default writes to capsules/ and needs you to specify the capsule name, including version, by hand. but maybe by fiddling with capsule's output directory and with the capsule name lein deploy can be tricked into pushing a capsule

shriphani20:01:19

hm interesting.

shriphani20:01:44

and if a third party includes this project’s coordinaties in their dependency (say), then would it all still work ?

jonahbenton20:01:41

hmm, i don't believe so. capsule is for producing runnable applications that require additional configuration or packaging beyond what's possible with an pure java jars and uberjars. A third party would not able to utilize a capsule .jar as a library both because a capsule on the inside doesn't look like an uberjar, but more importantly due to the same limitations that were already being worked around. if it was possible to smoothly package and utilize native code in the existing jar and uberjar formats then solutions like capsule wouldn't exist

jonahbenton20:01:54

but if what you're trying to do is produce a library that consumes this other library, you should be able to just do that

jonahbenton20:01:16

it would be incumbent on the consumer to manage their own jvm configuration

jonahbenton20:01:27

you can just use capsule for your own internal testing

jonahbenton20:01:04

e.g. have one project, a library, that consumes this native library, and have a second project that uses capsule that consumes the first and tests and so forth

jonahbenton20:01:31

then you can push the first library and point to the second as an usage example

shriphani20:01:21

@jonahbenton: would the first library in your example use java.ext.dirs or would it include this as a dependency ?

amacdougall21:01:26

@mikeb: I'm trying out Foundation in my app, and I've run into a couple of issues. To begin with, as soon as I started interacting with the database, I got a bunch of debug logging in the REPL. I'm sure this is very handy for development, but it should be off by default! I was able to use an insert query to write to my database, but when I tried a select query, I got this result:

(pg/qry-> conn (pg/select :users {}))

=> NullPointerException   clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:301)
That query should simply evaluate to SELECT * FROM users;, right? I did get the same result when I used a template query:
(pg/qry-> conn (get-users {:offset 0 :limit 30}))
Any idea what I'm doing wrong? ...come to think of it, I should open an issue instead. Slack is not great for async communication...

cddr21:01:34

Is it possible to mutate slots in a defrecord? I feel like I need to do this to implement a java interface which has an "init" method which sets up state that might be used later by a "process" method.

ghadi21:01:48

not in a defrecord, but only in a deftype @cddr. It's intentionally obtuse: mark the field with ^:volatile-mutable unless you really know what you're doing

ghadi21:01:12

then you can use set! from within the body of the deftype

ghadi21:01:05

this sets up a java mutable field with the volatile marker

cddr21:01:05

Thanks. Is this an "idiomatic" thing to do when interoping with java or is there a better way?

cddr21:01:36

Or maybe I need to provide more info about the java interfaces

ghadi21:01:43

it's an unfortunate reality of interop with interfaces that assume mutation

ghadi21:01:18

you can also use a non-mutable field in your defrecord that is an atom

ghadi21:01:26

that's the other common alternative

ghadi21:01:13

you can reset! / swap! it , etc.

cddr21:01:28

Yeah I thought about that. But I got stuck at how to initialize it as an atom. Is there a way of defaulting fields in a record?

ghadi21:01:12

commonly you see a defn that serves as the constructor

ghadi21:01:07

btw, if you do (defrecord Foo [a b c]) you get two extra functions for free: ->Foo for a positional constructor taking a b c, and map->Foo taking a map

cddr21:01:21

Yeah but I don't have control over construction. I just have to give the java code the name of a class that implements the interface (this is samza)

ghadi21:01:29

you can build in the defaulting using map->Foo

ghadi21:01:14

StreamTask?

ghadi21:01:40

which is the field you need to remember?

ghadi21:01:55

kafka & samza are really stupid about this

cddr21:01:55

local storage

ghadi21:01:42

i only see

process(IncomingMessageEnvelope envelope,
                      MessageCollector collector,
                      TaskCoordinator coordinator)

cddr21:01:00

Oh sorry. Actually it's InitableTask

cddr21:01:24

MyStatefulTask

ghadi21:01:07

just use an atom until it doesn't work for you anymore

ghadi21:01:23

oh, you can't provide a constructor..

cddr21:01:53

Not as far as I can figure out.

ghadi21:01:00

volatile-mutable it is then

ghadi21:01:17

But you may have to gen-class...

cddr21:01:47

OK Thanks.

jonahbenton22:01:10

hey @shriphani: the first library would not/could not refer to java.ext.dirs. there is no way to specify that sort of external-to-the-jvm configuration in a library. the second project- like a sample or test application- would be where an example or roadmap could be provided

mikeb23:01:43

@amacdougall: I think there's a problem with the way you've defined the db spec. it should be (def-datasource ...) with the dash, not a standard def with a map.