Touch the firehose of ds106, the most recent flow of content from all of the blogs syndicated into ds106. As of right now, there have been 92388 posts brought in here going back to December 2010. If you want to be part of the flow, first learn more about ds106. Then, if you are truly ready and up to the task of creating web art, sign up and start doing it.

From Daniel – Day 1 on Clojure

Posted by
|

So I started reading Clojure in the seven languages in seven weeks book. Right off the bat, I feel a little discouraged already since Tate compares Clojure to Lisp, and I know nothing about Lisp. I love the star wars reference in the book. Clojure is like Yoda :) .

I like how the book says that Lisp is the oldest commercially active language after Fortran, yet, I’ve never heard of it in the business world.

Reading about how Clojure uses the JVM excites me as I primarily program in Java at my internship/job. I like when Tate says “Clojure and Java desperately need each other. Lisp needs the marketplace that the Java virtual machine can offer, and the Java community needs a serious update and an injection of fun.”

I can relate to this quote as a java programmer. There definitely needs to be an injection of fun. Java can be hard to wade through with data encapsulation and hiding within its object oriented design. It’s not always fun to have to constantly thinking about those things when programming.

Day 1:
I’m currently taking a break at work. I have been working with java for about 3 hours so far today. I was told to restructure my code to avoid data being changed outside of a certain class. I’ve spent the last hour or so restricting that code. My brain is a little “fizzed” right now. On to learn some Clojure.
In the introduction, Tate mentioned that Lisp uses a list structure where the first element is a function name and the rest of the list is parameters. Right off the bat with Clojure, Tate has us typing (println “Give me some Clojure!”). Looking at that syntax, we can clearly see the Lisp in it. “println” is the function name and first element in this list followed by the string “Give me some Clojure!” as a parameter. Function calls have to be in parenthesis too in order to keep this form. Interesting.

Wow, Clojure uses prefix mathematical notation. This stuff hurt my brain when we learned it in Data Structures. I had a hard time with it then, I guess I better refresh myself on this stuff. It makes sense that it would use the prefix notation as it uses Lisp’s list structure where the function is first followed by parameters. So the expression (+ 2 2 2 2) makes sense to call the “+” function on 2, then apply it to each element in the list.

As I continue to read, everything about data types seems relatively straightforward. Lists, vectors, strings etc are all easily understandable. It was when I got to maps that I was thrown off. Retrieve a value by passing a key as the first value of a function makes sense. This would be a typical use of a key value pair in any other language. Then Tate introduced this “maps are also functions. Keywords are also functions:” The example was user=> (:luke mentors); where :luke is a key and mentors is the name of the map. This is backwards! But :luke can be a function, it looks itself up in a map. Apparently you can use any data type as a key or value. This sounds like JavaScript to me.
The section about Binding seems pretty complicated to wrap my head around. I had to read this section twice to make sense of it. It seems to have similar functionality to SML when it comes to lists.

Alright! After Day 1 I was introduced to Clojure pretty successfully. I’ve seen the general syntax with braces for lists, vectors, and maps. I seem the simpler forms of Booleans, characters, numbers, keywords, and strings. I saw how the ordered containers lists and vectors were different. I saw some function definitions with how and where the name goes with the parameter list and the function body. The documentation option was really simple! I’m still a little shaky on the binding thing, I will probably have to reread that section a third time.

Add a comment

ds106 in[SPIRE]