Fork me on GitHub
#clojure
<
2015-10-20
>
jeremyraines00:10:06

Could somebody give me any pointers to when / why classLoaders become a concern? I’m not familiar with them, but I’m trying to do something like this: https://github.com/uswitch/lambada

jeremyraines00:10:54

and I’m getting errors which seem to indicate that I need to do something like what he does in https://github.com/uswitch/lambada/blob/master/src-java/uswitch/lambada/ClojureLambdaBase.java but I don’t understand what’s going on there

cfleming00:10:17

@jeremyraines: What are the errors you’re getting?

cfleming00:10:53

What that code is doing is setting the thread context classloader to a specified loader. This is (generally) what Clojure will use to load its classes

jeremyraines00:10:03

java.lang.NoClassDefFoundError

cfleming00:10:14

That sounds like a likely candidate

jeremyraines00:10:43

thanks. When do you need to do that? Always with java packages? (I’ve mainly only worked with cljs so far)

cfleming00:10:24

So I don’t know very much about how Lambda works

cfleming00:10:46

But you’ll probably need to do that from some Java code, before Clojure itself is loaded.

cfleming00:10:06

How is your app started up?

jeremyraines00:10:38

actually I’m not sure how lambda starts it up either

cfleming00:10:25

So lambda, at some point, will call into your code, and at that point you’ll probably want to load some Clojure code and execute it.

cfleming00:10:48

You’ll need to find what that point is, I guess it instantiates an instance of a class, or calls an interface you provide?

cfleming00:10:51

I don’t know.

jeremyraines00:10:03

as far as I can tell it is getting into the Clojure code

cfleming00:10:09

Are you using lambada, or Lambda directly?

jeremyraines00:10:16

just parts of the java deps can’t find their own deps

cfleming00:10:40

Are you sure the jars for those deps are on the classpath?

jeremyraines00:10:12

that might be the issue. there’s this jar with the alexa-skills-kit library that I had to install via lein-localrepo because it’s not on maven

cfleming00:10:14

It might be a classloader issue, but it could also just be that the deps aren’t in the right place, or something similar

cfleming00:10:38

Are you deploying an uberjar, or something?

cfleming00:10:21

Ok, if you look in the uberjar, are the classes there?

cfleming00:10:35

Maybe the lein build isn’t doing what you expect.

jeremyraines00:10:30

how do you look in an uberjar?

cfleming01:10:45

Depends on your platform. It’s just a zip, so you can open it with a zip tool. If you have easy access to a unixy command like (like OSX), jar tvf your-uberjar.jar should show you the contents.

jeremyraines01:10:12

so, I’m not totally sure which class I’m looking for, but the first part of the error message referenced org/apache/commons/io/IOUtils which I do not see in the jar

jeremyraines01:10:02

and it is coming from a classLoader: java.net.URLClassLoader.findClass(URLClassLoader.java:381)

cfleming01:10:10

Ok, so that’s the problem, almost certainly (unless Lambda provides that class)

cfleming01:10:42

I don’t think that classloaders are your problem, I think your build isn’t adding all the deps to the uberjar

jeremyraines01:10:49

did something in the alexa-skills-kit jar not fully specify it’s deps? or how would that happen

cfleming01:10:25

That’s possible, yeah. I don’t know that jar, but that seems likely.

jeremyraines01:10:04

so I haven’t done it, but that jar is in their java examples that they hand out for you to deploy to lambda

jeremyraines01:10:29

thanks for your help, though. I’m not really even sure of a good next question to ask.

Doug Kirk01:10:53

@jeremyraines: It seems you need to add commons-io to your lein dependencies list so it'll fetch it for you.

jeremyraines01:10:08

i’ll try that

Doug Kirk01:10:34

[commons-io/commons-io "2.4"]

jeremyraines01:10:17

now it can’t find com/fasterxml/jackson/databind/ObjectMapper

Doug Kirk01:10:06

[com.fasterxml.jackson.core/jackson-databind "2.6.3"]

Doug Kirk01:10:35

You can see this is an iterative process when the dependencies aren't declared simple_smile

Doug Kirk01:10:45

Eventually you'll get them all

Doug Kirk01:10:25

BTW, I have a Chrome "search engine" set up for keyword mvn like so:

Doug Kirk01:10:54

then I can type mvn, tab, and the query and it'll search for the library

jtackett01:10:31

@kumarshantanu: Yep got it all working, thank you

cfleming02:10:37

Does anyone know why I can’t bind Compiler/LOADER using binding?

nowprovision06:10:49

@cfleming, doesn't it have to be marked with :dynamic?

nowprovision06:10:18

(:dynamic (meta Compiler/LOADER))

blueberry07:10:55

clojars is accessible again

cfleming07:10:50

@nowprovision: No, the issue is that you can’t use it with binding since that requires a symbol referring to a var. with-bindings works.

nowprovision08:10:43

is there anything comparable in functionality to korma that doesn't internally use var resolution features everywhere? i.e. I dont want global singleton entity definitions

nowprovision08:10:20

even though I can late bind the conn/pool to the entity during component start etc.. it still feels hacky, defining relations in a non global way leads one down a macro-expand rabbit hole eventually revealing code like this https://github.com/korma/Korma/blob/master/src/korma/core.clj#L589

nowprovision08:10:42

sql honey looks interesting but it looks like it doesn't handle deserializing joins, only query building

jaen09:10:29

I don't think there's anything like korma, at least in active development. But while I understand not wanting to have a global db connection, what's wrong about global entity definitions? (genuine question)

alqvist09:10:16

Anyone know if I can use Sente with a clojure client?

alqvist09:10:33

jaen: ok thank you

nowprovision09:10:09

jaen, fair question, I guess Im just uncomfortable with them, since we're not binding the default-connection I can't see a reason for them to be global, also Im a little paranoia that im introducing state somehow, in my very simple domain model though I've decided Im just going forgo the relation, that way I can use create-entity it seems

nowprovision09:10:17

I still tweaking it but I should able to model the join explicitly and woohoo (pointless win..) no defentity..

jaen09:10:28

But aren't they just as global as a def is? I imagine you're using defs, right?

nowprovision09:10:04

no defs, before I would assoc to the component a defentity bound to conn

jaen09:10:09

I don't see them any worse as doing (def something {...}) which I don't find bad at all

jaen09:10:45

But I don't think entities are in any way bound to a conn

jaen09:10:52

That's just a map describing a table

jaen09:10:57

So it doesn't have any state

nowprovision09:10:05

(assoc :webhooks (database webhooks-entity conn))

nowprovision10:10:07

true, hmmm.. i might need to rethink this

jaen10:10:14

And connection is used only when executing the query - https://github.com/korma/Korma/blob/master/src/korma/db.clj#L307-L311

jaen10:10:29

I think you're inflicting too much pain for yourself needlessly

jaen10:10:36

I'd keep using defentity

jaen10:10:42

I'd just not define the default connection

nowprovision10:10:57

yeah agreed... I guess defentity aren't too bad.. you're right

jaen10:10:02

And use with-db macro with the component you created

asolovyov10:10:13

anybody uses prismatic/schema 1.0 here? I'm not sure how I'm supposed to replace s/both (which is deprecated) with s/conditional...

asolovyov10:10:28

ah, it seems just replacing s/both with s/conditional works

yehonathan12:10:53

what is the perf of persistent vector random access?

yehonathan12:10:33

I'm expecting it to be 2-3 times slower than first element access of a list

yehonathan12:10:36

(get v 10000) vs (first s)

yehonathan12:10:50

I ran benchmarks on lighttable

yehonathan12:10:45

both take the same time

yehonathan12:10:48

how is it possible?

Alex Miller (Clojure team)12:10:09

That doesn't sound like a very good benchmarking environment to me.

donaldball12:10:57

Tim Crayford has a useful talk on benchmarking pitfalls: https://www.youtube.com/watch?v=0tUrbf6Uzu8

Alex Miller (Clojure team)12:10:02

The time complexity should be O log base 32 for a vector lookup and I agree with your expectation that it should be a bit slower than first on a list as it's going through 2-3 levels of tree

nowprovision13:10:41

@asolovyov you'll get a instance that might

nowprovision13:10:22

instatiant okay, but when used against s/check,validate throws a npe, in some scenarios you do have to make changes between s/both and s/conditional

nowprovision13:10:59

in many cases if you can just use s/pred with a predicate that has an 'and' e.g. ▾ src-cljs/ | 6 (s/pred #(and (string? %) (> (count (strings/trim %)) 0)))

nowprovision13:10:31

if you do as conditional iirc it's (s/conditional s/Str (s/pred #(> (count (strings/trim %)) 0)))

asolovyov14:10:16

@nowprovision: but s/pred doesn't give nice errors...

nowprovision14:10:06

true, i ended up doing something hack with that as still a step from lisp list to a human friendly (def not-blank (with-meta (s/pred #(and (string? %) (> (count (strings/trim %)) 0))) {:constraint-msg "must not be blank"}))

nowprovision14:10:16

Im rolling back a lot of decisions frequently at the moment, so possible that I won't feel the same tomorrow, Im just experimenting atm and recognized the same s/both deprecated to s/conditional issue you came across

asolovyov14:10:47

yeah, it kinda sucks

asolovyov14:10:55

plus s/both never had nice messages

asolovyov14:10:03

ok, I'll have to experiment a bit as well

nowprovision14:10:22

I think with custom predicates it will be quite difficult to go from a quoted list to a friendly meaning automagically, but if you come up with a way I'd love to see it

danielgrosse14:10:08

When I start an REPL an go into the namespace with (in-ns) I get the error „unable to resolve symbol“ What I’m doing wrong?

nowprovision14:10:16

@danielgroosee have you quoted the symbol e.g. (in-ns 'clojure.string)

nowprovision14:10:54

think (could easily be wrong) you may need to require it too if not already loaded (require 'acme.whatever) (in-ns 'acme.whatever)

danielgrosse14:10:47

I have a namespace but when I go into it with (in-ns ’project.core) the defn functions are not available. As if it creates a new namespace

nowprovision14:10:15

and you've required it first?

danielgrosse14:10:28

No just trying

danielgrosse14:10:04

Now I get a file not found Exception

nowprovision14:10:45

what exactly are you type at the repl, and what is the physical file path of the component you are loading (can be important with dash to underscore rules etc..)

nowprovision14:10:12

component -> namespace

danielgrosse14:10:42

I have to get more into the project. There is some error, I can’t understand now. I will contact the owner. Thanks for your help

oli17:10:38

any advice for dealing with nil values in prismatic schema

roberto17:10:47

not sure what you mean. Can you elaborate?

oli17:10:00

i'm using compojure api and have defined a schema

oli17:10:21

the api takes an input and uses it to query a database

oli17:10:33

some of the return values from the database are null

oli17:10:03

i put all the return values into a tree structure which matches the schema

oli17:10:12

then try to return that

oli17:10:22

but it fails validation

oli17:10:38

{:AddressLine2 (not (instance? java.lang.String nil))}

oli17:10:01

i get the why - just not sure what to do about it

jr17:10:11

{:AddressLine2 (s/maybe s/Str)}

oli17:10:20

seems to erase valid data...

roberto17:10:11

schema shouldn’t be modifying any data

oli17:10:37

:AddressLine2 (not (instance? java.lang.String {:schema nil}))

christianromney18:10:29

@oli helps to see one record. would be best if you could post a complete record as clojure data as well as the schema definition

oli19:10:12

@christianromney: i think i figured it out

oli19:10:02

i'm using the schema as a template to populate data into and adding (s/maybe ...) changes how that's happening which in turn breaks things...

christianromney19:10:33

@oli cool glad you got it working simple_smile

oli19:10:51

@christianromney: rubber ducking... 😛

oli19:10:25

not sure i'm not overcomplicating this - is there an approved way to insert values into a schema? i'm using a zipper to traverse the schema and inject values based on the schema keywords

oli19:10:22

works now that i'm checking if the type of the next node = schema.core.Maybe

warn4n20:10:28

Rich would obviously be the best person to chime in on whether that is an accurate representation of his views. Not sure if it’s worth @ ing him for this simple_smile. The viewpoint attributed to Rich certainly makes a lot of sense to me… as does most of what Rich says. But I’m sure there are some things that seem to make sense to me that Rich would not agree with.

warn4n20:10:31

I guess it’s more interesting to chime in on the viewpoint described itself anyway, rather than meta-discussions of whose views it does or does not represent.

warn4n20:10:49

That’s probably what you meant simple_smile

warn4n20:10:13

Clearly many Person classes have been written and a growing number of new ones are written every day.

warn4n20:10:49

Clearly none of them capture what it means to be a person.

favila20:10:44

Anyone know the rationale for transit-java (and thus clj) returning its own URI type (which datomic does not recognize as a URI in transactions) instead of java.net.URI?

warn4n21:10:49

@borkdude: thanks for sharing that link. a really good and concise explanation of one part of the clojure philosophy IMO. or of principles of simplicity that go way beyond clojure itself

warn4n21:10:33

Thing is, it could easily be confused with “pre-OO” or procedural thinking. But I think it’s really “post-OO” or functional thinking. The simplicity beyond complexity, in the words of some probably misattributed quote from someone. (of course FP is really only “post-OO” in the chronology of mainstream adoption)

borkdude21:10:17

@warn4n: I hear that a lot: but what you describe is procedural. I'm like: so what?

borkdude21:10:14

one could argue 'procedural' means something different than a functional language with higher order functions

jaen21:10:24

I'm not sure though why domain modelling is wrong, I see DDD being usable with a functional langauge as well. Unless that's not what is meant by domain modelling?

borkdude21:10:22

I don't think anyone said domain modelling is wrong. It's just done differently. I don't agree with the first answer on my question on Quora.

jjw21:10:01

Anyone have experience with Yesql interacting with postgres? I’m having trouble trying to pass a nil parameter.

Alex Miller (Clojure team)21:10:39

favila: transit-java and -clj just commit to a pretty minimal interface for uris (rather than Java's java.net.URI which is much heavier and has some pretty weird semantics for equals and hashcode)

Alex Miller (Clojure team)21:10:23

favila: because uri is an extension type though, you can supply your own read handler for the uri type to construct java.net.URI instead

favila21:10:06

@alexmiller: I know, was just surprised and didn't understand the rationale. Had a datomic transaction blow up with a transit-supplied uri, was a head-scratcher until I realized it was not producing a java.net.URI type.