Quote: Heinlein - Specialization is for Insects
I had used this quote in Wash, Cook, Clean and Iron, but thought that it deserved to also be available in it's own right.
Continue reading →A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.
Robert A. Heinlein
Cover Song - I'll Fly Away by Rev. Gary Davis
A blue's rendition of I'll Fly Away by Rev. Gary Davis. It's awesome. You need to listen to it.
Continue reading →Learning Clojure - Implementing cat
As I wrote previously, I am learning the Clojure programming language as one of my personal Learning Projects.
Previously, I presented my implementations of echo
, the classic Unix command-line utility. Next on the list is cat
, a useful utility for writing information out to the screen from a file or the standard input. Well, technically it writes to the standard output, but the default destination for the standard output is the screen, so it works out the same in the end.
Now, let's take a look at the code:
(ns cat.core
(:gen-class))
(use 'clojure.java.io)
(defn readAndPrintFile [name]
(with-open [rdr (reader name)]
(doseq [line (line-seq rdr)]
(println line))))
(defn readAndPrintStdin []
(doseq [ln (line-seq (java.io.BufferedReader. *in*))]
(println ln)))
(defn -main
"Simple implementation of the Unix cat utility."
[& args]
(if (= (count args) 0)
(readAndPrintStdin)
(doseq [a args]
(readAndPrintFile a))))
Continue reading →
Learning Clojure - Implementing echo
As I wrote previously, I am learning the Clojure programming language as one of my personal Learning Projects.
Previously, I presented my implementations of true
and false
, the classic Unix command-line utilities. Next on the list is echo
, a useful utility for writing information out to the screen. Well, technically it writes to the standard output, but the default is that that is the screen, so it works out the same in the end.
Now, let's take a look at the code:
(ns echo.core
(:gen-class))
(require '[clojure.string :as str])
(defn -main [& args]
(if (= (count args) 0)
(println)
(if (= (first args) "-n") (print (str/join " " (rest args))) (println (str/join " " args)))))
Continue reading →
Learning Clojure - Implementing true and false
As I wrote previously, I am learning the Clojure programming language as one of my personal Learning Projects. Naturally I started with hello world because there are a ton of examples of hello world available and just being able to get it working proves that you're gotten your development environment setup correctly.
Now that I have moved past hello world, I am ready for the first programs that I will have to write myself. No copy and paste of a complete working version, or because I am using lein
I get a copy supplied everytime I start a new project. So, it is time to write the simplest programs that it is possible to write in almost every programming language I've ever used, the equivalents of the Unix utilities true
and false
. These are so simple to write because they do nothing except exit and pass an integer value back to the operating system. In the Unix world, where these come from, the convention is that a zero indicates success and a non-zero indicates failure, with again the convention being that the false
utility returns a one. (Naturally, other utilities are free to return any non-zero value they wish, but `false is going to give you a one.)
A challenge when setting up the projects was finding that Clojure does not allow language keywords as filenames, so true.clj
and false.clj
were not options. Necessity brings out invention, so I named them cljtrue.clj
and cljfalse.clj
. Not the most exciting names, but they work. (That's actually pretty good considering that I'm a graduate of the Jocko school of naming things!)
Now, let's take a look at the code:
Continue reading →