---

Tuesday, June 3, 2008

Old Languages - Lisp

I have a certain nostalgia for old programming languages. So here are a few notes about Lisp.

Lisp is an old old language - it was originally specified in 1958. I spent a happy three years in the 1980's on a small team writing a frame-based constraint-satisfaction system that automated the layout of chemical plant. 

I also implemented an Object-Oriented Database System (CLOSQL) in it as part of my PhD. So, don't think of it as a 'novelty' language, this is an elegant and powerful language.

Its a functional language - that is, everything is expressed as a function using a parenthesis notation. Thus you would add 2 and 2 together by writing:
(+ 2 2)

It uses lists as its data structure, and lists can contain lists to make trees.

Even the programs themselves are lists. The first part of the list (the head) is the name of the function and everything else in the list are its arguments.

(let ((n 0))
(loop
(when (> n 10) (return))
(print n)
(incf n)))

See how the 'let' function contains a list of variables (just n in this case) that are then in scope for the rest of the 'let' command.

Lisp has loads of clever stuff, like being able to create anonymous function blocks called lambda blocks that can be passed around as arguments to functions, in much the same way as blocks in Smalltalk and Ruby.

Remember 1958 !!

No comments: