After The Clojure Course

I am ready to work on my final assignment for the Clojure Course. Overall, I give CodeLesson a thumbs up, but I will have comments on things that could be improved, should they desire them. In other words, if there is a survey, I will be filling it out.

Here are the highlights of what I’ve learned, and it’s not sequences, recursion, emulating objects, inter-operating with Java, or other technical concepts. Instead it is a new way to look at testing — it is just too easy to write tests not to — and ways of creating different layers of code logic, from which DSLs are created. Oh yes, and that means looking at where macros could be used.

I will take additional time to read the macro and functional programming chapters of Amit Rathore’s Introduction to Clojure, because there are some well written areas — the book very good overall — but some of the most complicated areas are just downright elegant. I will continue to look for Clojure articles, because I have found that even sources like the older edition of Stuart Halloway’s Programming Clojure has good pedagogy for particular topics.  Blogs like Alex Miller’s Pure Danger Tech have downright great tutorials, and I turned to some of these during the course, just so I could wrap my head around new concepts.

Finally, I need to start writing code and not worry where I am on the Clojure experience ladder. Instead, I will write tests, look for logical separation, and, no matter how simple the task, my experience tells me, you have to write code in and struggle with a computer programming language to achieve mastery in it.


Clojure Exercise Well

I found some nice Clojure exercises http://www.cis.upenn.edu/~matuszek/cis554-2010/Assignments/clojure-01-exercises.html .

Basically, practice makes perfect, especially with recursion. Oh yes, I learned recursion taking a course in data structures long ago, and re-learned recursion when learning C. I have never used recursion in production that I can remember. That is not true with Lisp dialects.

There are other ways to remove list duplicates, but I wanted to roll my own on this one. I made two mistakes. One was not having an else for the second if expression. The other was checking for null of new-seq instead of (first new-seq).


(ns repl-test
  (:gen-class)
  (:use clojure.contrib.command-line)
  (:require [clojure.contrib.string :as cstr])
  (:require [clojure.contrib.trace :as ctr])
  (:use clojure-csv.core))

(def d3 [1 2 3 1 4 1 2])

(defn x-in-seq [x temp-seq]
  (if (nil? (some #(= x %) temp-seq))
   x))

(defn f1
  [in-seq]
  (loop [new-seq [] cur-seq in-seq]
    (if (nil? (first cur-seq))
      new-seq
      ;(if-not (nil? (ctr/trace (x-in-seq (first cur-seq) new-seq)))
      (if-not (nil? (x-in-seq (first cur-seq) new-seq))
         (recur (conj new-seq (first cur-seq)) (rest cur-seq))
         (recur new-seq (rest cur-seq))))))

(defn -main
[& args]

(println (f1 d3)))