Fork me on GitHub
#clojure-uk
<
2018-03-08
>
practicalli-johnny00:03:55

So I guess I am one of the few who listens to music on my laptop with Bluetooth headphones... good to know

dominicm09:03:33

I mean, I do that now. But I know plenty of my colleagues don't. To them, having that there is just a battery drain / potential source of crashes.

maleghast09:03:24

I listen with BT headphones on Arch - was not that hard to set up ...

danm09:03:57

Tiiiiiired

maleghast09:03:53

Hello Clojure Land 🙂 A very good morning to All 🙂

Rachel Westmacott10:03:19

Random core function of the day:

-------------------------
clojure.core/key
([e])
  Returns the key of the map entry.

thomas10:03:14

keys is good as well. returns all the keys IIRC

reborg10:03:13

Guess key and 'val` are there mainly for interop:

(import '[java.util HashMap]) 
(map key (HashMap. {:a 1 :b 2}))

dominicm10:03:53

I thought it was for performance.

reborg10:03:15

also true, agree

yogidevbear11:03:01

Can someone explain the difference to me between these four approaches?

(map key (HashMap. {:a 1 :b 2}))
(map key {:a 1 :b 2})
(keys (HashMap. {:a 1 :b 2}))
(keys {:a 1 :b 2})
I'm guessing that keys is doing something similar to (map key ...) under the hood?

yogidevbear11:03:38

The output is the same for all four when I run them so curious about the difference and pros/cons inherent in each

bronsa11:03:56

@yogidevbear map key is lazy, keys is not

bronsa11:03:02

but otherwise no difference

bronsa11:03:23

what’s the point in wrapping a phm in a hashmap?

reborg11:03:11

@yogidevbear the wrapping with HashMap was there to showcase key where first would not work. But normally, you'd go keys to get all the keys from a map. (map key) or (map first) produces the same list lazily (and maybe there is a decent use case for that, but probably not many).

yogidevbear11:03:39

Cool, thanks for the explanations 👍

yogidevbear11:03:36

So I've started wrapping my code in non-lisp languages in parentheses without thinking 😆

reborg11:03:53

that's a great achievement! It happens to me all the time 🙂

bronsa11:03:56

I’ve been writing ocaml for the past 6 months and I still destructure constructors like (Foo x, y) instead of Foo (x, y)

bronsa11:03:14

but yeah as @reborg says — prefer keys over map key

bronsa11:03:27

the rationale for key/val is with e.g. find

bronsa11:03:40

which returns a MapEntry

dominicm11:03:09

Found this on Stack Overflow:

user=> (defrecord X [a])
user.X
user=> #user.X {:a 1}
#user.X{:a 1}
I'm rather mortified.

bronsa11:03:05

beware that

user=> #user.X{:a (+ b c)}
#user.X{:a (+ b c)}

bronsa11:03:31

there’s an implicit quote

bronsa11:03:51

which is makes this syntax almost useless

bronsa11:03:14

apart from roundtripping read/print

thomas12:03:32

@yogidevbear yup, I have done that as well... most confusing was that the Python editor I was using didn't flag it as bad syntax... took quite a bit of time before I found that one.

dominicm13:03:19

That's so... weird. @bronsa may we have a history lesson on this one?

bronsa13:03:44

I’m afraid some of the discussion might have happened internally at relevance

dominicm13:03:11

> This syntax satisfies the need for a general-purpose Java class construction reader form. However, not all Java classes are considered fully constructed after the use of their constructors. Therefore, serialization support is not provided for any Java classes by default. For instances such as these, Clojure will continue to provide facilities via print-dup in the known ways. So it's a general purpose way to initialize a class? Interesting again.

bronsa13:03:37

the [] variant is

bronsa13:03:44

the {} one works only on IRecords

reborg14:03:14

wow didn't know about the deftype variant (maybe I've seen it printed, but never payed attention)

mccraigmccraig15:03:57

what deftype variant @reborg ?

reborg15:03:09

(deftype Point [x y])
;; user.Point
#user.Point[2 2]
;; #object[user.Point 0x19648c40 "user.Point@19648c40"]

reborg15:03:27

minor value, I always use (Point. 2 2), plus the reader version has quoted arguments (like the defrecord)

bronsa15:03:29

yeah it’s not used much

bronsa15:03:51

I’d say the only use case is serialization

bronsa15:03:02

not supposed to be used in code

reborg15:03:04

actually, how do I get the deftype to print for serialization, do I need to extend the printer?

bronsa15:03:24

for some reason there’s no print-dup or print-method defined for IType

mccraigmccraig17:03:47

PSA: if anyone was considering trying cassandra or DSE on DC/OS - don't bother. leave it a while, unless you enjoy ops catastrophes

otfrom17:03:08

any tl;dr on the problem?

mccraigmccraig18:03:07

@otfrom it looks like the DSE DC/OS universe package has never seen any serious usage and has a bunch of config problems - it installs ok and runs, but the configuration is screwy... datastax-agent has a fixed -Xmx128m and OOMs when you do any big ops (this can be fixed), the cassandra node containers can't be configured with the required ulimits (this can't easily be fixed afaict), nodetool doesn't work, probably because of some container networking issue

mccraigmccraig18:03:34

it fools you in to thinking that it's working ok, and then suddenly you find dropping and recreating a few MVs is killing your cluster stone dead!

mccraigmccraig18:03:19

it would be nice to have DSE run on DC/OS, but i've had enough hassle now and i'm going to deploy it to some naked centos nodes alongside a smaller DC/OS cluster

otfrom18:03:33

sounds reasonable