Fork me on GitHub
#clojure
<
2017-02-19
>
joshjones02:02:17

I have a java object that's being created by a factory class, so I'm not directly instantiating it. I'd like to add some state to the object, just a simple integer field, and maybe getter/setter for this field. I can proxy or gen-class a new type, but is there any way I can actually add state and methods, given that I do not directly create the object?

sgdread03:02:06

Hello, which libraries are used to do database work? I found java.jdbc package, is there any widely-adopted layer above it? Just trying to figure out what's the standard approach.

danielsz06:02:36

@sgdread Many options. One of the latest offerings is toucan. https://github.com/metabase/toucan

qqq10:02:38

is there a cleaner way of writing:

(doseq [[x y] (map vector xs ys)]
  ...)
it seems like there ought to be a shorter way of writing this

moxaj10:02:33

@qqq (map (fn [x y] ...) xs ys)?

qqq10:02:57

well, map is lazy right while doseq is not right? so I'm running a number of assertions

qqq10:02:12

so I think doseq would exec the assertions wheras map would create a lazy list which does not exec the assertions until they are needed

residentsummer10:02:20

you can wrap it in doall

moxaj10:02:21

wrap it in a doall

qqq10:02:49

hmm, clever

residentsummer10:02:14

but I’m not sure if it’s more readable than you initial expression

qqq10:02:18

while clever ppl are here, is there a hsorthand for (every? identity ...)? it's basically (apply and ...) but I can't do the latter becaseua nd is a macro not a function

qqq10:02:45

@residentsummer it does work better because (did not put this in original question), the (fn [ x y] ... ) is an existing function which has a simple name, so it ends up being (map foo xs ys)

residentsummer11:02:06

qqq: looks like (every? identity …) is the best option...

residentsummer11:02:42

I wonder why every? does not have unary variant though

qqq11:02:18

pull request 🙂

amyma12:02:35

hey guys. Im studying the source of clojure.core

amyma12:02:46

as to the definition of if-not

amyma12:02:12

why not just

igrishaev14:02:44

how can I run a REPL session in my code directly? Say, I have a (try-catch) block and I'd like to run REPL in catch clause in my current ns. Thanks.

seancorfield14:02:02

You can start a repl server using functions in clojure.tools.nrepl

igrishaev14:02:14

I'd like to have the following:

(try (call-my-func) (catch Throwable _ (repl/start)))

igrishaev14:02:51

when repl/start is called, a new interactive REPL session is started, so I can check the exception content. Then I interrupt it and the programm continue to execute.

igrishaev14:02:50

you know, like in Python we do import pdb; pdb.set_trace()

tbaldridge14:02:18

unfortunately I don't think it's possible to do it to the extent python does. the JVM optimizes away a lot of things (like locals), so I don't think it's possible to just fire up a repl in the context of where an exception is thrown.

joshjones17:02:54

@qqq so in your example earlier, mapping vector -- you said that you are running assertions, presumably to ensure that the resulting data is valid. But where are you performing the assertions?

qqq20:02:16

joshjones: in the ... of the (doseq [[k v] (map vector ks vs)] ... )

joshjones20:02:06

ah, so in the doseq block itself -- but then you don't get to hold on to your result, but i guess that's stuff you've already worked out

qqq22:02:19

right, the doseq isn't about generating values, it's about running assertions

mruzekw18:02:10

I’m attempting to integrate a servlet (from Auth0) into a clojure app. It requires context-params be set in web.xml Does anyone have any pointers here to make it work? I’m following this guide: https://auth0.com/docs/quickstart/webapp/java

mruzekw18:02:25

Looks like they have a java library which I could use instead. https://github.com/auth0/auth0-java

mruzekw18:02:43

But if anyone has any pointers for the above problem, please reply

mobileink19:02:41

what is the problem you're running into?

risto20:02:26

can you write a spec for a protocol? something like:

(defprotocol Foo []
  Bar
  (s/fdef bar ...)
  (bar [this x] ...))

davidtpriest22:02:25

Hello everyone. Just wanted to say hello! Just starting my clojure journey. Very excited, and looking forward to meeting some of you.

tech_hutch03:02:17

@U46T0D7ED same. I've been listening to a lot of talks by Rich Hickey. I keep hearing more good things about the language.

davidtpriest22:02:53

@U46LM0HR6 Seriously. I know i have a decent learning curve ahead of me, but i feel like the end will justify the means. It just seems so rich in possibilities and how it can do a lot in less code just blows my mind.

byron-woodfork22:02:46

For what it's worth, the learning curve for Clojure is a lot smaller compared to several other languages. That's been my personal experience at least.

zane22:02:05

That's interesting to hear, @U08PR8LJZ. What was your language background prior to Clojure?

byron-woodfork22:02:42

@U050CT4HR I actually consult. So I've written code in several languages.. Ruby, Java, Clojure, Scala, C# ... To name a few. Clojure was the simplest for me to wrap my head around. The biggest obstacle was getting used to functional programming. But once you figure that out, things fall into place

zane22:02:13

Right on.

zane22:02:30

I'm curious, did you have any editor woes when you were first getting started? I know that can be an obstacle for new Clojurians.

byron-woodfork23:02:37

@U050CT4HR yup! Luckily though, you can find a nice groove in a few different editors once you've established the plugins. I prefer vim. With a few different plugins added to it for Clojure specifically. I've been testing out Atom more recently and I like that as well. I hear good things about Cursive, but there is a price tag with that.

davidtpriest00:02:20

@U08PR8LJZ thanks. I kinda feel like since i don't have a ton of previous programming experience it won't be as hard as say, having years of experience, and then learning clojure. Not sure if this is true though haha.

zane16:02:37

I used to be a TA for Northeastern University's introductory computer science course which was taught in a dialect of Scheme. Our experience was that students who did and did not have prior programming experience faced different challenges, though it was hard to say which whose challenges were greater.

zane16:02:06

Either way, I'm sure you'll be fine! I'm excited for you!