Fork me on GitHub
#clojure
<
2015-12-21
>
gfredericks01:12:59

don't worry, I forgot I was going to do that so I haven't done it yet

cigitia04:12:44

Let's say I have two protocols, A and B, and a bunch of types that each implement either A or B but not both. Let's also say that I have a function f that, given an instance of one of those types, needs to behave with one of two possible behaviors, depending on whether its input satisfies A or B. What's the most idiomatic way to do this? • `f` could use (cond (satisfies? A input) ..., (satisfies? B input) ..., :else (throw (ex-info "Needs to satisfy A or B" {}))) (though apparently satisfies? is currently quite slow (http://dev.clojure.org/jira/browse/CLJ-1814))? • A third protocol C could be defined, which each of the types must implement in addition to A or B, and which has a single method ab-type that returns either :a or :b whenever A or B is respectively also implemented. f could then use (case (ab-type input) :a ... :b ...)? • Maybe multimethods (though I can't yet think of a way how one would)? • Something else?

rhansen05:12:37

Wouldn't it be more natural that A and B protocols include a method that f needs, or include f as a method?

rhansen05:12:48

Otherwise, I would say that your first point (using satisfies?) is the most idiomatic.

slester08:12:46

I'm doing Advent of Code in Clojure as a relative newbie. Placed 90th today! @borkdude

borkdude09:12:32

I'm lagging behind, only doing it on the weekends and elaborate on details, just to learn a new language simple_smile

jrychter09:12:10

Is there a core.async function that is the opposite of onto-chan? Basically, one that does (async/<!! (async/reduce conj [] ch)) to get a collection out of a channel?

wotbrew10:12:25

@jrychter: I am not aware of such a function in the library itself, its easy to write a naive version if you can guarantee your channel will close - however it cannot work with all channels which I guess is why such a fn isn't in the core.

jrychter10:12:08

@danstone Thanks. I wondered if I was missing something.

d-t-w10:12:02

(async/<!! (async/into [] ch)) is probably what you're looking for.

d-t-w10:12:36

(defn into
  "Returns a channel containing the single (collection) result of the
  items taken from the channel conjoined to the supplied
  collection. ch must close before into produces a result."
  [coll ch]
  (reduce conj coll ch))

jrychter10:12:56

@d-t-w Yeah, I just thought there would be a single function for this operation. Clojure naming isn't always easy to guess.

borkdude10:12:58

is there something in emacs/cider that can format a file that contains edn like pprint does?

robert-stuttaford10:12:08

anyone using jars and know how to use -classpath and also pass args to the -main defined in -classpath?

jrychter10:12:07

Hmm. I'm writing a stateful transducer and it behaves differently when attached to a core.async channel than when run through sequence or into. In particular, my arity-1 flushing function gets called twice (?).

jrychter11:12:53

Is it expected for (async/to-chan (line-seq rdr)) to hold on to the head and exhaust memory?

jrychter11:12:20

(`onto-chan` used similarly does it too)

bronsa11:12:44

vote it up I guess

jrychter11:12:56

Well that one is a complete showstopper for my current Clojure work. 😬

bronsa11:12:58

@jrychter: if you can add it as a comment to that ticket, it might help getting it prioritized

jrychter11:12:54

@bronsa: I'm just curious how is that not a showstopper for anyone who puts any significant amount of data through core.async? Am I missing something?

bronsa11:12:12

@jrychter: I've been wondering about that myself

jrychter12:12:00

I'm processing log data through a core.async pipeline with transducers. My 8GB heap is gone within 30 seconds of starting.

bronsa12:12:24

@jrychter: if you could try that with a patched core.async applying that ticket's patch and see if it does indeed fix the leak, (and if so, report that in the ticket), that would be helpful in getting the patch forward

bronsa12:12:39

if you don't have time for doing this nevermind though simple_smile

jrychter12:12:08

@bronsa: not until I somehow finish that data analysis job I took on…

jrychter12:12:03

Ok, I see why it doesn't affect more people: it's not all go blocks that leak memory, just ones that use lazy sequences created elsewhere.

bronsa12:12:04

yes, it's only on closed over sequences

trancehime12:12:36

Who here has used yesql I just want to confirm something

rhansen12:12:28

Though I mostly use hugsql nowadays

jrychter12:12:00

@bronsa: Ok, I panicked too early. I can work around that by writing a non-leaking-onto-chan that uses future, loop and blocking puts instead of a go block.

bronsa12:12:20

sure, there are workarounds

trancehime12:12:39

Are a series of rows returned via a SELECT query in the form of a lazy sequence or as a vector

bronsa12:12:41

but.. 😕

trancehime12:12:02

reason is that I would like to add an extra element to the sequence of rows returned by the query

trancehime12:12:13

I'd guess it was lazyseq?

rhansen12:12:43

I think it is a lazyseq, but I don’t think the actual query is lazy.

trancehime12:12:25

Yeah, that sounds about right. I just needed confirmation

trancehime12:12:56

also, hugsql? What an adorable name

jrychter12:12:09

@bronsa Thanks for letting me know about this bug — I could have wasted even more time on this if it wasn't for your help.

rhansen12:12:44

@trancehime: You should check it out. Hugsql fixed every problem I had with Yesql. I’ve even written a postgres-async adapter for it that uses core.async. Cool stuff.

jonpither14:12:17

What Clojure SVG libs are people using?

octahedrion14:12:40

@jonpither: just Om, Reagent or Quiescent

pupeno17:12:55

A colleague of mine (@jjconti) is experiencing a weird error when using cljs-time. What makes it weird is that the same code works on my machine. Same version of ClojureScript and cljs-time: http://stackoverflow.com/questions/34401358/error-formating-date-in-clojurescript Any clues whit might be going on?

roberto17:12:32

and same project?

pupeno17:12:42

No, different project.

roberto17:12:44

it could be that something else in the project is causing it...

pupeno17:12:15

Yeah, but we haven’t been able to figure it out.

potetm17:12:31

@jrychter: Hey man, I think you might have just solved a production bug for us by bringing this up at the right time simple_smile Nicely done.

rcanepa17:12:24

What is the best way to coerce incoming data in JSON format to a desired shape/schema?, Which libraries are used for that purpose?, I am trying to apply the coerce function from prismatic schema to transform a JSON but it fails trying to convert a string date to a java.util.Date.

rcanepa17:12:10

I read about clj-time and about transit?, could this problem be solved using one of those libraries?

stuartsierra17:12:19

@rcanepa: Transit can send any arbitrary values, preserving their type, but you have to be using Transit on both sides of the communication. It doesn't transform JSON from arbitrary sources.

jaen17:12:13

@rcanepa: I had no problem with such coercion. Granted, I used clj-time, but had no problem with stock schema coercion.

rcanepa17:12:58

@stuartsierra: Good to know that, because I don’t have much control over the client side.

solicode17:12:45

Do both projects use the same version of Figwheel?

rcanepa18:12:48

@jaen: Maybe I am not understanding correctly how to use the coerce feature. Right now, I am doing a very simple test and it is failing. Could I be doing it wrong?

rcanepa18:12:16

I am getting this error: #schema.utils.ErrorContainer{:error (not (instance? java.util.Date a-java.lang.String))}

jaen18:12:22

IIRC json-coercion-matcher doesn't coerce dates

jaen18:12:58

You'd have to merge with it

jaen18:12:26

(merge coerce/json-coercion-matcher {java.util.Date your-function-that-takes-string-and-returns-java-util-Date})

jaen18:12:29

Something like this

jaen18:12:40

As you have it no coercion happens for Dates so it gets a string and that doesn't match the schema.

solicode18:12:11

I guess that’s reasonable behavior given that there are so many different Date types.

jaen18:12:18

Yeah, I agree.

jaen18:12:44

Some people wouldn't want to have to depend on JodaTime, some wouldn't like stock dates.

jaen18:12:05

Were it all Java8 then it probably could standardise on the new API, but alas, that's all too new.

jarredlhumphrey18:12:44

is there a way to make core.test print the string facts in testing declarations (ie. (testing “print me” … ) ) when running the tests? similar to how midje allows for (change-defaults :print-level :print-facts) in your .midje

rcanepa18:12:52

Thanks @jaen, I am going that way !

pupeno18:12:41

@solicode: we are also suing the same version of figwheel

solicode18:12:56

@pupeno: Hmm, interesting. I'm not sure if Figwheel is causing the problem or not, but maybe it's worth a shot to try and take Figwheel out of the equation and see what happens. Other than that, I'm not sure if I have any other ideas.

jrychter18:12:07

@potetm: hey, glad to take one for the team! May I suggest that you also upvote the core.async bug in JIRA and possibly add a comment describing how it affects you?

potetm18:12:50

@jrychter: Can easily upvote. Have to confirm before commenting though simple_smile

alexmiller19:12:52

I hope to have a few min to look at some of those async things this week

manderson19:12:46

Anyone have any recommendations for a microservices/rpc library like Finagle but in Clojure? I'm aware of the Clojure/Finagle wrapper, but wondering what else might be out there...

blissdev20:12:19

Is there a styleguide or best practice for commenting functions in clojure?

stuartsierra20:12:23

@blissdev: I try to make functions small enough that the docstring is the only comment needed.

ghadi20:12:13

it's a noble goal stuartsierra

ghadi20:12:38

"Justify this if it's over 7LOC"

stuartsierra20:12:54

Other than that, just the old Lisp conventions: end-of-line comment begins with one semicolon, block comments in a function begin with 2 semicolons.

blissdev20:12:12

Thanks, I was completely forgetting about docstrings, that’s the way.

magomimmo20:12:48

And at the start of line with three semicolons

blissdev20:12:18

ah, similar to this?

lvh21:12:35

If I have a superclass A and a subclass B that overrides all of the methods in A, does (.x ^A a) call the implementation from A, or B?

stuartsierra21:12:19

@lvh It calls the implementation of whatever concrete type a is, just like Java.

lvh21:12:30

stuartsierra: Thanks! That’s what I was hoping for simple_smile

stuartsierra21:12:42

I don't think it's possible in the JVM to call a super-class method implementation from a sub-class which overrides it.

lvh21:12:58

stuartsierra: Right; even Method.invoke uses regular method invocation rules

bronsa21:12:31

it might be possible using invokespecial