Thursday, June 23, 2005

Day 1: Thoughts and notes on readings

I thought that I would start reading Common Lisp: A Gentle Introduction to Symbolic Computation. Before starting this blog I had learnt a little of lisp already so this blog won't start at the beginning of my push to learn Lisp. I have already obtained some familiarity with lists, the functions car and cdr, some of the mathematical functions and the "listener" from viewing the divx movies: Structure and Interpretation of Computer Programs, Video Lectures.

I think that one of the core concepts in lisp is "evaluation". Lisp runs in a loop: it reads input, evaluates and prints output. The evaluation part could be thought of as execution of code. It is then this process evaluation that is the key to understanding Lisp. The basics are
  • A number evaluates to a number. If you type in 1 and hit return the result of evaluation is printed as 1
  • A string is represented as characters enclosed in double quotes. If you type in "foobar" and hit return the result of evaluation is printed as "foobar
That is all well and good but things get interesting when you type in foo. You get an error. This seems to be because when lisp tries to evaluate foo it doesn't know what to do. It isn't a string or a number so lisp thinks it is a symbol. In this case lisp has not been told what that symbol represents so it shows an error. You can stop the error by telling lisp not to evaluate the symbol by quoting it. This means putting a ' in front.

The next biggest thing to understand about lisp is functions. At the same time you would need to know about lists because they look the same ie data and program code look the same in lisp. It seems to be easier to talk about functions first. A function is like:

(print "hello, World!")


when lisp evaluates that it prints out "Hello, World!" then prints out what (print "hello, World!") evaluates to which is also "Hello, World!". So you get two "Hello, World!"'s.
One might say list is like the following on paper:

(1 2 3)
("foo" "bar")

but when you type that in lisp tries to evaluate it as a function and says "illegal function name 1" or "illegal function name "foo"". Basically lisp assumes it is a function and evaluates it accordingly. Once again you can stop this error by telling lisp not to evaluate the list by quoting it by putting a ' in front.

'(1 2 3 4)

That is it for now. I have read about more in the book but I haven't made notes about cons car and cdr functions, some predicates and math operations and the assocation between symbol-name symbol-function and lambda. More on this later.

No comments: