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
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:
Post a Comment