I don’t like infixes
All this stuff began with a tweet of mine in response to @unclebobmartin. While Mr. Martin said "I am becoming ever more convinced that clojure is the functional language to use", I argued that Clojure is the opposite of Literate Programming as (+ 1 2) is very far from my natural way of thinking 1 + 2.
My opinion is that the prefix notation of Clojure, and the resulting parenthesis pollution, makes this language very hard to read.
Then @fogus pointed out that there is nothing literate about the infix way of representing (< a b c d e f g). That's true, if we think of a C like implementation such as:
a<b && b<c && c<d && d<e && e<f && f<g
But, fortunately, we have Scala:
package net.fl.clojure object ClojureDemo { case class RichList (list : List[Int]) { def isOrderedBy(f: (Int, Int) => Boolean) : Boolean = list match { case Nil => true case x :: Nil => true case x :: y :: xs => f(x, y) && listConverter(y :: xs).isOrderedBy(f) } def isAscendingOrdered = isOrderedBy(_ < _) } implicit def listConverter (list: List[Int]) = new RichList(list) def main(args : Array[String]) : Unit = { println(List(1, 2, 4).isOrderedBy(_ < _)) println(List(1, 20, 4).isOrderedBy(_ < _)) println(List(1, 2, 4).isAscendingOrdered) println(List(1, 20, 4).isAscendingOrdered) } }
So the lispish (< a b c d e f g) becomes List(a b c d e f g).isAscendingOrdered or, if you want to be more flexible List(a b c d e f g).isOrderedBy(_ < _)
