Came across an excellent (http://loufranco.com/blog/files/category-20-days-of-clojure.html) of blog posts by Lou Franco, where he uses the SICP videos as input to learn more about Clojure.
His explanation of HashMap implementations in Clojure, using multimethods, as well as pointers on parallelizing functional programs are very well written. I’m currently on his day 10 post.
--
If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.
I just finished skimming through Bruce Eckel’s Thinking in C++ book – available for free from his website.
Volume 1 covers the basics pretty well and I didn’t really do much more than glance at it, but volume 2 is highly recommended for its marvelous treatment of the C++ STL containers and algorithms.
--
If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.
This post contains a list of changes between Clojure 1.1.0 and 1.2.0 that would affect you if you’re reading Stuart Halloway’s “Programming Clojure”.
It looks like you’d have to replace,
(use ‘)
(filter indexable-word? (re-split #”\W+” “A fine day it is”))
with
–> (“fine” “day”)
since the str-utils module got renamed to string, and the re-split function to split.
--
If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.
I was looking for a suitable library for Clojure that would work like Python’s BeautifulSoup or lxml – and found enlive.
An excellent tutorial here http://github.com/swannodette/enlive-tutorial.
--
If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.
I was trying to figure out how to AOT compile a Clojure program, in order to really see some fast execution times. The simplest way to describe AOT compilation would be how its done in Java,
``
javac file.java
java file
The invocation of the Java compiler (javac) is the pre-compilation of the source file, which is then loaded by the JVM in the next step. In the case of Clojure, when a program is run using,
``
clj myfile.clj
The code is first compiled, and then executed – resulting in large amounts of time for the output to be displayed even for simple programs.
The AOT compile process turned out to be trickier to set up than I expected, so I thought I’d put it out there for all those who get stuck after reading the original documentation at http://clojure.org/compilation.
Firstly, the directory structure for my experiment looks like this,
I created dir1, and its subdirectories as below. The code is in clojure/examples/ and the classes/ directory is the default compile.path – something that the documentation neglected to mention. Without this path, compilation WILL fail.
``
/dir1/.clojure
/dir1/clojure/
/dir1/clojure/classes
/dir1/clojure/examples
/dir1/clojure/examples/hello.clj
This file is used with my clj script, that can be obtained from (http://mark.reid.name/sap/setting-up-clojure.html).
It contains a list of directories that are to be specified to the Clojure compiler at compile time. The file looks like,
``
/dir1:/dir1/classes
This code of course is the default from the Clojure website, as a test.
``
(ns clojure.examples.hello
(:gen-class))
(defn -main
\
(println (str "Hello " greetee "!")))
The next step is to invoke the Clojure REPL using the clj script, from the dir1 directory.
Type in the following to compile the program in the clojure.examples namespace,
``
Clojure 1.2.0-master-SNAPSHOT
user=> (compile 'clojure.examples.hello)
clojure.examples.hello
user=>
Success! And the resulting output of the classes directory is,
``
$ ls /dir1/classes/clojure/examples
hello$_main__5.class
hello$loading__4946__auto____3.class
hello.class
hello__init.class
And lastly, to run this program as any other Java program, you can use,
``
java -cp ./classes:/opt/jars/clojure.jar:/opt/jars/clojure-contrib.jar clojure.examples.hello Viksit
Hello Viksit!
Also, I highly recommend Stuart Holloway’s book “Programming Clojure”. Its turning out to be an excellent read.
--
If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.