Clojure's "zero?" has some quirks

In short, Clojure's zero? isn't exactly like nil? and true? and others. It checks different numeric types and throws if given a non-numeric type.

This post was written about Clojure 1.8.0.

Clojure has a few functions that do equality checks, like nil?, true?, false?, and zero?. The docs all look about the same for these functions. nil? "returns true if x is nil, false otherwise" and the rest look similar.

But despite similar documentation, zero? is a little bit different from the rest.

Let's start by looking at true?. It accepts anything as an argument; a boolean, a string, whatever.

(true? true)   ;; true
(true? false)  ;; false
(true? "str")  ;; false

In contrast, zero? throws an error if the argument isn't a number.

(zero? 0)      ;; true
(zero? 42.0)   ;; false
(zero? "str")  ;; throws java.lang.ClassCastException

This was a little surprising to me! It's not documented and it also doesn't match the other equality checkers.

zero? is also a little smarter about different numeric types. zero? handles cases that a simple equality check doesn't.

(= 0 0)      ;; true
(= 0 0.0)    ;; false
(= 0 "str")  ;; false

(zero? 0)    ;; true
(zero? 0.0)  ;; true
(zero? "0")  ;; throws java.lang.ClassCastException

You could write a version of zero? that works like nil?, which won't throw on non-numeric input but will still work for various number types.

(defn safe-zero? [x]
  (and (number? x) (zero? x)))

(safe-zero? 0)      ;; true
(safe-zero? 0.0)    ;; true
(safe-zero? "str")  ;; false

zero? isn't vastly more complicated than I expected, but it's a little more nuanced than I thought at first glance.

Petition to open source Flash

From the petition:

Adobe is going to stop distributing and updating Flash player and the Shockwave player. That's ok.

However Flash along with its sister project Shockwave is an important piece of Internet history and killing Flash and Shockwave means future generations can't access the past. Games, experiments and websites would be forgotten.

Lessons learned from last week's cyberattack

From a post on a Microsoft blog:

We need the tech sector, customers, and governments to work together to protect against cybersecurity attacks. More action is needed, and it's needed now. In this sense, the WannaCrypt attack is a wake-up call for all of us.

Think of the journalists

From "Won't Somebody Please Think of the Journalists?", a talk:

The only way to make journalism a safe practice is to make the Internet, and cell phones, and thermostats, and robot vacuums, and every other technical tool out there safe for everyone.


Talking about journalism helps people disengage the fear part of their mind and remain level-headed or even hopeful.

I think digital privacy is important. I think it's hard to convince others that it's important...this is fuel for my arguments!

Ball lightning

From "Ball lightning: the coolest thing you’ve never heard of":

Ball lightning looks like a floating glowing fuzzy ball of light, usually a few inches to a few feet in diameter. It floats or moves around rooms, airplanes, open areas – and occasionally through solid objects. It usually lasts for a few seconds or, rarely, minutes, and then disappears, silently, or with a popping sound, or sometimes even a loud explosion and a surge of electricity through nearby objects. This surge often sets on fire, blows up, or electrocutes nearby objects – everything from cows to VCR players to people. Ball lightning usually appears under in the same circumstances as regular old lightning: during major storms, flying through clouds in planes, etc.

Ball lightning is super cool!!