Fork me on GitHub
#clojure
<
2015-09-10
>
gtrak00:09:02

had better luck with extending assert-expr

mikera00:09:38

@gtrak I wrote cljunit to get JUnit integration with clojure.test - works nicely in Eclipse and with Maven : https://github.com/mikera/cljunit

amacdougall02:09:52

@nberger: I think I'm getting to the bottom of this POST thing. The Swagger UI didn't work for completely baffling reasons that might be bugs in its own code... once I'm out of the woods, I'll try to reproduce and make a test case, but if you want to have some fun, do a +swagger Luminus project and try out the /minus and /divide post endpoints in swagger-ui. For me, if I edited the arguments, I'd get JS errors. I haven't used ring-logger yet -- I wanted to remove Clojure-side request generation from the equation. curl -v and judicious logging have proven really useful, and it looks like the error is in my code to begin with (surprise surprise), but I will hook up ring-logger soon to test the mock request format against what I know to be working in curl. In the meantime, before I can produce error-free schema-based output, it's time to read up on coercion... I'm sure I'm going to look back at this and laugh. Hopefully I won't be in a padded cell at the time.

nberger02:09:14

Haha. I've seen it working in an app but using :body instead of :body-params... it works with swagger-ui, but I'm using peridot instead of ring-mock for the tests. I'll see if I can give it a try with ring-mock tomorrow

amacdougall02:09:43

Don't worry about it! I did just get a reduced version working with curl. I'll see about the full version, and a tested version with ring-mock, tomorrow. Thanks for your suggestions so far. I look back at what I'm doing, and I realize that I've really been wrestling with very elementary stuff... I would be discouraged, since I pretend to be a "senior programmer" from 10 to 6 every day. In other languages, thank goodness. But really, the only way to learn anything is to begin with the acceptance that you know nothing.

nberger03:09:56

Isn't it that senior programmers are those who recognize that in the first place? 😛

amacdougall03:09:34

I don't know... sometimes I'm jealous of our summer interns, who know virtually everything. Clearly I forgot it all somewhere along the way.

beppu04:09:35

@profil - I believe that's possible.

profil07:09:07

@beppu: How do I do it?

profil07:09:33

@beppu: nvm, I already solved it yesterday, just took a while for it to iterate 😄

denik09:09:12

Does anyone remember the name of the clojure library that allows to add data to a thrown exception-map?

denik09:09:19

not= slingshot

oliy10:09:12

you mean ex-info?

denik10:09:30

@oily with ex-info I’d have to catch, assoc to ex-data and and rethrow. I thought I remembered a library that would make that more concise + additional benefits

beppu11:09:37

@denik: This is a tangent, but when talking to Common Lisp people, they frequently complain that Clojure doesn't have a condition/restart system as described here: http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html

beppu11:09:09

However, I've been meaning to check out http://docs.caudate.me/ribol/ which is such a system implemented for Clojure.

beppu11:09:42

@profil: I see you figured it out, but in the repl, you can just redefine things at will and they take effect immediately.

denik12:09:47

@beppu I see. It seems try/catch with added ex-data can work similarly to Common Lisps signal/handler. Only restart is not that easy.

rauh12:09:04

I think hara/signal is the new ribol. Edit: Wrong: It's hara/event

beppu12:09:40

I'm still trying to wrap my head around how to use conditions and restarts. I've come to appreciate good error handling, and if there's something better than the traditional try/catch (which isn't bad), I'd like to know.

beppu12:09:56

@rauh: Is ribol deprecated in favor of what's in hara?

rauh12:09:58

@beppu: I think so. I was wrong with calling it "signal". It's hara/event

rauh12:09:46

@beppu: Yes, ribol is deprecated

beppu12:09:03

@rauh: Thanks, good to know.

ljosa14:09:18

Does clojure have read-time evaluation, similar to #. in Common Lisp?

Lambda/Sierra14:09:00

ljosa: Yes, via #=, but it's not "officially" documented and generally not recommended.

ljosa14:09:50

thanks, I’ll try not to use it unless I really have to then.

beppu14:09:15

@stuartsierra: Out of curiosity, how do you use #=?

beppu14:09:53

n/m figured it out.

ljosa14:09:01

> '(+ 1 #=(+ 2 3))
(+ 1 5)

erik_price18:09:43

In the highlighted function parameter list, what is idiom being used for the second parameter? (Specifically, line 148: & [callback]) https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/client.clj#L137-L148

erik_price18:09:10

Is that to allow an arbitrary number of parameters, only the first of which (which should be named callback in the function body) is actually used?

beppu18:09:35

@erik_price: It's for pulling values out of a hash-map. See the bottom of section 3.3.3 here: http://www.braveclojure.com/do-things/#3_3__Defining_Functions

erik_price19:09:44

beppu: I’m specifically curious about line 148, which seems to be a vector destructuring applied to the varargs parameter. It appears to be destructuring the first element of the varargs, and what I’m really wondering is… why would one do this? Is it a useful idiom in Clojure to write functions that take varargs but only use the first one?

beppu19:09:44

@erik_price: I've never done it that way myself, but I guess it's a convenient way to tack on one more optional param at the end.

erik_price19:09:04

beppu: thanks. i sort of thought so… just wondered if that was common.

gtrak19:09:28

anyone know offhand if (into {} transducer m) is faster than (persistent! (reduce-kv .. (assoc! ..)?

gtrak19:09:48

i feel like destructuring the kv map entry would slow things down

gtrak19:09:58

in the transducer

jakemcc19:09:56

@erik_price: I’ve found it is better to replace that style of optional argument with explicit multiple arities

tcrayford19:09:49

@jakemcc: agree. It shows up in docstrings properly etc. Plus for callbacks, you can have your lower arity thing pass a callback that does nothing, which cleans the code up a bunch (esp if the callback is called in more than one place)

gtrak19:09:04

turns out reduce-kv is about twice as fast on a large map

gtrak19:09:02

(defn remove-nil-vals1
  [m]
  (if-let [s (seq m)]
    (persistent! (reduce-kv (fn [acc k v]
                              (if (nil? v)
                                acc
                                (assoc! acc k v)))
                            (transient (empty m))
                            m))))

(defn remove-nil-vals2
  [m]
  (if-let [s (seq m)]
    (into (empty m) (filter (fn [entry]
                              (some? (val entry))))
          s)))

tcrayford19:09:48

using criterium with non default jvm settings?

gtrak19:09:08

not rigorous

gtrak19:09:22

with (def nilmap (into {} (map vector (range 1000000) (interleave (range 1000000) (repeat nil)))))

tcrayford19:09:49

in different jvms for each criterium run as well?

tcrayford19:09:10

(measuring things on the jvm is really hard)

gtrak19:09:29

well, just trying to get a feel for it simple_smile

gtrak19:09:42

is reduce-kv iteration faster than the transducer stuff

tcrayford19:09:58

it's hard to do "just a feel" on the jvm sadly 😞 Thing is so complex to measure

tcrayford19:09:33

(I've seen per differences of ~ 10 thousand times in the wrong direction due to benchmarking mistakes. 10000 is probably bigger than 2)

tcrayford19:09:47

sorry, don't wanna piss on your measurements

gtrak19:09:10

no, I agree, if I were posting this to clojure-dev I'd be yelled at simple_smile

gtrak19:09:29

but I'm still just learning transducers and trying to establish the new rules of thumb.

gtrak19:09:47

seems like a single boot script would be the easiest way to do criterium tests

ghadi19:09:29

gtrak: those aren't 100% equivalent -- one is a nil? check the other is some?

ghadi19:09:42

at least unify them and see if the 2x holds

ghadi19:09:16

maybe try (filter (comp some? val))

ghadi19:09:56

or (remove (comp nil? val)) and hope for surprising data points

gtrak19:09:44

well, remove calls complement, and some also calls not, the not has to go somewhere simple_smile

gtrak19:09:35

seems consistent either way

gtrak19:09:28

comp some? val was my first try

gtrak20:09:08

lazy-filter is indeed a bit slower than the transducer version though

gtrak20:09:58

which matches intuition

gtrak20:09:10

is there a coll-reduce implementation for persistenthashmap? I think it might still be creating a seq in that case.

profil20:09:30

I am translating a mathematical function into clojure code and get a function that is a lot slower than the "equivalent" python function. The python function takes about 2 seconds to run, but my clojure version takes at least 25-30 seconds. What am I doing wrong?

profil20:09:58

The function contains two nested sums, which I solve by using two nested reduce. The maths looks like this http://mathb.in/42688

profil20:09:33

And my clojure function looks like this, https://www.refheap.com/109401

profil20:09:04

The zetas/patterns are nested lists

profil20:09:14

Any hint is welcome

meow20:09:11

@gtrak: I've been having a lot of fun with transducers lately here: https://github.com/decomplect/ion/blob/master/src/ion/ergo/l_system.cljc

meow20:09:43

Haven't spent much time on performance optimizations, however.

meow20:09:30

@profil: does that code have to be all in one function, or could it be split up?

profil20:09:24

@meow: No reason for it to be in a big function like that, I would split it up, but wanted to know if I do something very wrong first simple_smile

profil20:09:41

its very ugly right now

meow20:09:57

well, speaking from experience, when I start getting frustrated with code that isn't working its often because I've got a function that is doing too much. Lately I've worked very aggressively at keeping my functions to a bare minimum, and I'm much happier with the results.

meow20:09:06

It seems like the simplest thing, and it is. But I've had to work to break myself of bad habits from the past.

meow20:09:23

Another benefit I've recently experienced. I used to be happy when some code I was working on worked and passed some unit tests. And that's still great. But with really, really small functions, I find that many of them don't really need tests (shhh, don't tell the test-driven folks). And then the functions that use those functions, which are also small and focused, well not only do they not really need tests but even better, I can fully grasp what they do so much faster and easier. I can compose all these functions I've written in my head. And for the most part, know that they will work. Just building things up, one layer at a time, each layer as thin and focused as the previous layer.

meow20:09:56

Old hat for all the functional folks here, but for an old OO guy I'm finally feeling the payoff of the functional approach, where the clojure functions I need are coming into my mind fairly readily, my own functions are just small compositions of clojure functions, and everything just builds up nicely.

profil20:09:43

Yeah, I agree about the small function part. But in this case I am forced to create closures because the inner reduce functions still needs data outside of their "call scope", which makes it a bit ugly..

jakemcc20:09:54

@profil: Also make sure the types of mu and nu support quick nth lookups.

profil20:09:13

@luxbock: Thanks, will check that

profil20:09:39

@jakemcc: Yeah, working on getting repeatedly to spit out vectors instead simple_smile

meow20:09:47

@luxbock: one of these days I'm going to start using type hints in my code

luxbock20:09:47

@meow they can be a bit tricky

meow21:09:30

Most of the code I've been working on is early development and in such a state of flux I really don't want to invest the time in optimization until the code matures a bit and settles down.

luxbock21:09:28

I think unless you are working with numerics or Java interop then they don't matter as much

profil21:09:36

Haha, converting my lists into vectors made the clojure function faster than the python version :D nth on lists is linear so

profil21:09:51

Thanks for the help guys!

estsauver21:09:00

@meow: I believe prismatic schema spits out type hints.

nberger23:09:07

> Does anyone remember the name of the clojure library that allows to add data to a thrown exception-map? @denik: did you find it? If not, what about https://github.com/gfredericks/catch-data?

denik23:09:38

I think I saw something else