Skip to content

Instantly share code, notes, and snippets.

@semperos
Last active January 17, 2019 14:38
Show Gist options
  • Save semperos/3a10cd6c0fa8481768978f43a80441c6 to your computer and use it in GitHub Desktop.
Save semperos/3a10cd6c0fa8481768978f43a80441c6 to your computer and use it in GitHub Desktop.
Clojure Inconsistencies

Clojure Inconsistencies

This document is a description of unexpected behavior in Clojure's language implementation, not a prescription as to how it ought to behave differently.

I enjoy using Clojure and find most of the language design decisions to be excellent. Please do not use this gist for unconstructive purposes.

;;;;;;;;;;;;;;
;; Numerics ;;
;;;;;;;;;;;;;;
;; + ;;
;; Expected:
(+ Long/MAX_VALUE 1)
;=> ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1526)
;; Unexpected:
(+ Integer/MAX_VALUE 1)
;=> 2147483648
;; - ;;
;; Expected:
(- Long/MIN_VALUE 1)
;=> ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1526)
;; Unexpected:
(- Integer/MIN_VALUE 1)
;=> -2147483649
;; N.B.: Clojure provides +' *' and -' which auto-promote numeric types.
;;;;;;;;;;;;;
;; Seq API ;;
;;;;;;;;;;;;;
;; Expected:
(take 2 [])
;=> ()
(drop 1 [])
;=> ()
(drop-last 1 [])
;=> ()
;; Unexpected:
(take-last 2 [])
nil
;; N.B.: nil is seqable so nothing should break about this inconsistency.
;; Expected?
(get "foo" :bar)
;=> nil
;; Unexpected, given the above:
(contains? "foo" :bar)
;=> IllegalArgumentException contains? not supported on type: java.lang.String clojure.lang.RT.contains (RT.java:846)
;;;;;;;;;;;;;;;;;
;; Complecting ;;
;;;;;;;;;;;;;;;;;
;; EJ: Consider metadata, and fact that only IMeta/IObj types can have it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment