Fork me on GitHub
#clojure-uk
<
2017-10-18
>
otfrom08:10:16

@jonpither emacs every day

otfrom08:10:23

couldn't get by w/o org-mode

Rachel Westmacott08:10:48

does anyone know a neat way to apply <, >, min, max to things that aren’t numbers, but could maybe be java Comparable?

dominicm09:10:31

sort-by takes < (for example)

mccraigmccraig09:10:04

i've done a reduce with a comparator fn in such circumstances @peterwestmacott - no neat trick though

dominicm09:10:09

So that's one option, it depends on what you want to do.

dominicm09:10:44

oh, you use compare apparently 🙂

Rachel Westmacott09:10:56

I wanted to say eg. (< offset-date-time-1 offset-date-time-2)

mccraigmccraig09:10:36

yeah compare is a good default comparator

dominicm09:10:25

(sort > [4 5 6]) there's definitely something going on with this. I think clojure functions implement the Comparator interface.

mccraigmccraig09:10:35

yes i think they do @dominicm - you can use any old 2-arg clojure-fn iirc

Rachel Westmacott09:10:38

there’s min-key which is quite nice

dominicm09:10:55

Interesting: sort actually creates a java array and uses it's sort method.

dominicm09:10:49

min-key/max-key are good for this sort of thing, yeah.

dominicm09:10:06

Is there any reason not to use the function from the date system you're using?

Rachel Westmacott09:10:43

eg: (sort (OffsetDateTime/timeLineOrder) [(OffsetDateTime/now) (.minusSeconds (OffsetDateTime/now) 15)]) ?

Rachel Westmacott09:10:14

apart from it being long and ugly, I’m mostly checking if dates are before/after each other, rather than needing to sort a lot of them so it would likely be more performant to call .isBefore

dominicm09:10:38

^^ that's what I meant, .isBefore

Rachel Westmacott09:10:52

I just wondered if there was a more general solution (either for all things, or more likely things that are already Comparable), but it sounds like I should just compose core lib fns or get specific

dominicm09:10:38

I think core has avoided have multimethods/interfaces for these things for performance reasons. But don't quote me on that.

chrjs09:10:41

Morning all.

dominicm09:10:03

I'm starting to get hungry, I have a horrible craving for bacon mayo.

dominicm09:10:13

all I have is cinnamon bagels.

thomas09:10:11

moin moin, we got back home late last night... our flight on Monday got cancelled 😡

Rachel Westmacott11:10:31

@dominicm that sounds likely re: performance

mccraigmccraig11:10:45

really ? protocols boil down to java interfaces don't they and are fast - is it not just hysterical raisins ?

Rachel Westmacott08:10:34

In the past I have experienced order of magnitude speed-ups by replacing collections of objects in Java with arrays of primitives. While Java interfaces may be ‘fast’ I suspect that numerical calculations have requirements that are a step beyond what other operations require. Being performant for intensive numerical work has fundamental implications for what your language can be practically used for.

mccraigmccraig09:10:41

right, yeah, arrays of primitives are often worth special-casing...

mccraigmccraig11:10:53

(where just ~ ∞)

Rachel Westmacott12:10:48

‘just’ is my favourite dangerous word