Fork me on GitHub
#clojure
<
2016-03-07
>
hiredman00:03:17

it is actually a reference to a book by william gibson

hiredman00:03:34

"hired man" not "hi redman"

Tim01:03:34

hi redman

joshg02:03:02

When using update-in, is there an idiomatic way to initialize the intermediate data structures associated with each part of the vector if they’re nil? I know about fnil, but that will only initialize the final data structure.

joshg02:03:25

For example, when executing (update-in {} [:a :b] conj 5), what if I wanted the map containing :b to be a sorted map instead of a hash map?

joshg02:03:56

I suppose I can just use multiple update-ins with fnil to initialize the intermediate data structures

markmandel03:03:14

Can someone do me a favor - this function is just recurring forever, and I can't quite see what I've done wrong 😕 can anyone see why this isn't working? https://www.refheap.com/90d3d4687e98bd9e9b367cb0b

markmandel03:03:29

I could use a second pair of eyes

jonahbenton03:03:01

@markmandel: use of local rest shadowing the var?

markmandel03:03:46

hrmnn... maybe.. lemme try that

markmandel03:03:23

https://www.refheap.com/db3f8aff0cce3720c1c79f2c1 < nope. Still just logs "Count: 330" over and over

jonahbenton03:03:40

your (rest points) is always pulling from the param

markmandel03:03:42

(Thanks for the help though)

markmandel03:03:56

oooh of course it is!

markmandel03:03:00

I need to change my destructuring

markmandel03:03:33

Thanks. Needed the second pair of eyes

markmandel03:03:27

that's better

viesti13:03:29

I’m trying to export utilities written in Clojure to a Scala application

viesti13:03:58

and having problems with libraries like riddley and clj-tuple

viesti13:03:17

both have clojure and java code

viesti13:03:04

and trying to load my library in scala, gives errors about these missing java classes

viesti13:03:53

this might not be the root problem… it seems like the dependencies that my utility library (written in clojure) aren’t visible to the scala application

viesti13:03:26

hmm, not that I’m writing this, might be that I’d have to add clojars resolver to sbt...

viesti13:03:53

hmm, doesn’t help either 😕

viesti13:03:52

thinking that transitive dependencies aren’t getting pulled in

viesti13:03:01

wonder why...

viesti13:03:07

sbt dependencyTree seems to confirm this

viesti13:03:59

there is a pom.xml inside the clojure library that I created, with dependencies listed

jstaffans14:03:33

@viesti: did you create an uberjar?

viesti14:03:20

no, but thought that it wouldn’t be necessary

viesti14:03:24

to package dependencies of a library that I publish to a local repository (S3) into a uberjar that is

dm314:03:21

are the jars on the classpath? do the jars contain the compiled java classes?

dm314:03:02

there must be a way to get the actual classpath from sbt

viesti14:03:29

looking at sbt dependencyTree and it doesn’t show the dependencies that my library has, so most probably sbt cannot get necessary libraries on the classpath

viesti14:03:54

thinking that is there something that sbt dislikes in the pom.xml generated by leiningen...

dm314:03:24

you can try with maven

dm314:03:51

check whether it will show the correct dependency tree

viesti14:03:10

ah true, mvn install or the like

viesti14:03:42

mvn install just copies the same pom.xml, doesn’t improve the situation 😕

manderson14:03:45

Are any of the clojurewerkz folks in here? Curious if anyone has a rough eta on when elastisch will have support for ES 2.X? The README states dev will begin after 2.2 release of elastisch, so didn't know if that had started. Thanks!

anmonteiro16:03:48

is it possible to have some methods in a defrecord be static?

base69816:03:27

isn't that just a defn that takes a type?

base69816:03:39

or a protocol?

anmonteiro16:03:50

what I wanted to do specifically was call a protocol implementation on the defrecord type

anmonteiro16:03:41

I'm generating records in a macro and I can't just dispatch on the type a priori

nonrecursive16:03:10

I’m using clojure.java.jdbc to read from a sql server db and for some reason the deployed app doesn’t read unicode characters correctly- has anyone else run into this? here’s the connection map:

{:subprotocol "jtds:sqlserver"
 :subname     "host:port/db-name"
 :user        user
 :password    password
 :useUnicode  "yes"
 :characterEncoding "UTF-8”}

nonrecursive17:03:32

nevermind I don’t think it’s jdbc-related

jonahbenton17:03:57

hi @anmonteiro: can you share more about what problem you're running into?

anmonteiro17:03:23

@jonahbenton: I'm creating records in a macro, and I have them implement a protocol (let's say (defprotocol IFoo (foo [this]))) I want to be able to call (foo generated-record) without instantiating it

anmonteiro17:03:11

atm I'm able to do it by also creating a multimethod implementation that dispatches on the generated record but this feels brittle

therabidbanana17:03:59

Anybody here know of a good example/library for HTTP clients with built in handling of caching (standard HTTP cache headers - etags/last modified)? It seems like I can write middleware to do it for clj-http - but hoping for this prototype I can use something off the shelf.

jonahbenton17:03:10

hmm- why do you need to generate record types if you aren't going to instantiate them? what role do the types play? if the types are just placeholders and are not data containers perhaps just use a keyword taxonomy- which plays well with multimethods- instead?

anmonteiro17:03:37

@jonahbenton: I'm going to instantiate them but I need those methods beforehand

jonahbenton17:03:31

hmm- and what the methods have to do is type specific and is pre-instantiation from a lifecycle perspective?

jonahbenton17:03:44

my intuition is failing me- can you share what problem is being solved? some kind of type registration? is there a reason it can't be done in the macro?

stuartsierra17:03:48

@fxposter: I don't know the current status of compatibility between tools.namespace and ns-tracker. At the time I wrote the article (2013), ns-tracker depended on an older version of tools.namespace.

nkraft17:03:26

I'm sure this has come up, but is there a method in Lein to deploy uberjars to a destination server? Not talking about deploy, but perhaps something with scp.

stuartsierra17:03:55

I have never tried to combine tools.namespace-style reload-on-command with any kind of automatic reload-on-every-request.

jonahbenton18:03:53

hey @nkraft application deployment is usually specific to the infrastructure-model, rather than package-model. There are lein plugins for heroku, aws (elastic beanstalk, pallet), immutant (jboss), and some others. What infrastructure model is your app running on?

nkraft18:03:24

@jonahbenton: It's running on local servers, nothing cloudish.

nkraft18:03:15

Just trying to save a step: right now I make an uberjar, then scp things around. It would be nice to have some option in lein that I could configure for any server, not just common cloud providers.

nkraft18:03:57

Something like that could be useful for deploying map/reduce jobs, too, possibly.

jonahbenton18:03:04

Sure, gotcha. So- the short answer is that multi-host application deployment and batch/service lifecycle is not lein's purpose or sweet spot. A tool to look at that is purpose built for these and other use cases and is infrastructure agnostic is Ansible: https://www.ansible.com/

jonahbenton18:03:29

An ansible playbook that scps some uberjars around to a list of hosts and restarts them is about 5 lines

nkraft18:03:26

I'm familiar with ansible. It's a good tool, though we use salt for similar things here.

nkraft18:03:17

I'm not sure that Lein's sweet spot doesn't include such things. I can use lein to deploy a web application to Heroku, for example, which is really only different from what I'm looking for in url and transport method.

nkraft18:03:41

Oddly there are numerous plugins to push to repositories. I do that with git.

nkraft18:03:09

Yet a search on clojars for "scp" comes up empty. Oh, well. I'll keep the current workflow for now.

jonahbenton18:03:49

Yeah- to my eyes the issue is what happens after the scp. Who picks up the uberjar and what do they do with it?

bijoy18:03:17

I have a multi module maven project, one module uses java clojure mix, from the container pom, I don't see an option to compile as it complains the inability to aot compile clojure and inability to find java reference (which I have a clojure source with :gen-class), appreciate if anyone can point me to an example multi module java clojure repo

nkraft18:03:34

I really wan't going for full automation in deployment. Just need to get it there. System resources pick it up and run it. Lein doesn't need to know about that.

dm318:03:17

@nkraft: I'd look at boot if you're running into lein limitations. Very easy to just run arbitrary code from boot

dm318:03:56

e.g. shell out and scp

hiredman18:03:57

bijoy: the clojure maven plugin may compile java and clojure in such an order that the java class isn't available to clojure when it is compiling

nkraft18:03:01

@jonahbenton: That's much closer to what I was looking for. Thanks!

hiredman18:03:18

bijoy: you might try and crib from https://github.com/clojure/tools.nrepl/blob/master/pom.xml since it has some java and some clojure source

nkraft18:03:50

@dm3 I knew someone would suggest boot. Maybe it's finally time to take the plunge.

bijoy18:03:24

Thanks hiredman, maven-clojure-plugin does decent job for single module, but could not find anything on a multi module setup, was looking out if any thing already exist

hiredman18:03:06

good luck, multi module maven builds are not an easy road to travel

hugesandwich18:03:30

I'm having trouble finding a good way to deal with a reflection warning with with-open. I've implemented a few protocols and reified an object using them, one of which has a close method, which calls an underlying Java close. The protocols are not in the same file as the reified object or my test code, so that might be part of the problem. The close itself works fine, but unless I type hint my constructor method with Closeable from Java, it's always putting up a fus about the reflection warning. I could move the close method to just be implemented with Closeable on the reified object, but that also doesn't help. Given it's reified, the type is dynamic and otherwise not needed anywhere else in the code. Am I stuck converting this to deftype if I want to rid myself of with-open reflection warnings? I see a few outstanding Jira tickets related such as: http://dev.clojure.org/jira/browse/CLJ-308

viesti18:03:36

just for the record, wasn't leiningen problem

jonahbenton19:03:45

@hugesandwich: hmm- you are seeing reflection warnings even with an object that reifies java.io.Closeable?

jonahbenton19:03:38

user=> (set! warn-on-reflection true) true user=> (with-open [a (reify java.io.Closeable (close [this] nil))]) nil

jonahbenton19:03:47

well, better to say this: user=> (with-open [a (reify java.io.Closeable (close [this] (println "closed")))]) closed nil

jonahbenton19:03:28

@bijoy: can you use the lein-maven-plugin https://github.com/abailly/lein-maven-plugin to allow lein to direct the build of the clojure/java submodule in accordance with rules in lein's mixed projects docs? https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md

hugesandwich19:03:43

@jonahbenton: no, I have implemented a reified object that implements Closeable, and when using it in another namespace in conjunction with (with-open [obj (make-obj]) it happens

hugesandwich19:03:02

I can type hint on the with-open itself to fix the reflection warning, but that is not a good solution

hugesandwich19:03:18

there are actually 2 close functions (from a java api), 1 that takes options as well, so I may want to implement a macro there anyway, in which case i can just wrap this manually or in the case of the 1-arity close, do a with-open with the type hint. Regardless, it's an annoying problem in projects where I globally watch for reflection

practicalli-john20:03:55

I can get a value from a map easily if I have the keyword. Is there an easy way to get a keyword in a map that matches a particular value (assuming all values are unique

practicalli-john20:03:56

Ah, just found map-invert thanks to this stack exchange question http://stackoverflow.com/questions/10612093/reverse-lookup-in-a-map

fxposter20:03:53

@stuartsierra: I see… anyway, thanks for the answer.

stuartsierra20:03:03

you're welcome.

jonahbenton20:03:38

@hugesandwich: to keep the type hint confined to definition rather than use, did you try: (defn ^java.io.Closeable make-obj [] (reify ... )))

hiredman20:03:50

@jr0cket: if you find yourself doing that often, I recommend getting familiar with clojure.set/index

hugesandwich20:03:45

@jonahbenton: see my previous comment, I did try that and it works, but as I said, it's not so nice, hence why I mentioned the macro.

hugesandwich20:03:05

@jonahbenton: I'd rather not push macros or type hints on people using this api

hugesandwich20:03:52

type hinting the make-some-obj fn as closeable also works, but again is not so good for various reasons

jonahbenton20:03:58

yeah. the implementation doesn't seem to lend any other alternatives. i can imagine a small patch to with-open to try a Closeable cast and fall back on duck typing

hugesandwich20:03:25

I think it needs to be changed per the jira issue

hugesandwich20:03:52

the strange thing is somehow I either must have not caught it or ignored it, but when I had everything in 1 file, I didn't have an issue I think. It was awhile ago though.

hugesandwich20:03:03

actually never mind that, i think I found something in my git history and it does throw a reflection warning, which makes sense. Using reify really exacerbates it.

jonahbenton20:03:37

yeah. the protocol approach is a nice idea, but everybody's code probably has a close function.

hugesandwich20:03:58

I think I'll just write a macro given the 2nd arity for close that the java api exposes and I wrap in my own protocol

hugesandwich20:03:01

thanks for your help

jonahbenton20:03:24

not much help, but interesting problem

hugesandwich20:03:58

I didn't think there was really a solution. It is an interesting problem and ugly things like throwing on closeable seem to be the only solutions right now.

josh.freckleton22:03:33

For practice, I'm doing Project Euler puzzles in Clojure and I find I often can't help but using loop/recur, is this idiomatic in Clojure, or is there usually a better way? Or am I wrong for even thinking loop/recur is not idiomatic?

weebz22:03:40

usually you can use reduce

rickmoynihan23:03:24

Does anyone have any good opensource examples of reducers and transducers in the wild?

rickmoynihan23:03:28

I'm especially interested in examples that use them for I/O sinks... e.g. reduce into this file etc

josh.freckleton23:03:09

@weebz: good resource, thank you!