(archive 'newLISPer)

December 9, 2005

The basic rules of LISP

Filed under: newLISP — newlisper @ 09:49

LISP is surprisingly simple. There are only a few things you should know to get started.

LISP works with lists of items. Each list is enclosed in parentheses. LISP tries to use the first item of the list as a function or method, unless you tell it not to.

Here’s some LISP code

(+ 2 2)

LISP sees the first item, the + sign, and tries to apply it to the other items in the list. This works out nicely, and gives the answer 4.

The next thing you have to know is how to stop LISP trying to evaluate lists like this. Put a single quote before the list:

'(+ 2 2)

LISP sees the quote and doesn’t apply it to the list, so the result is (+ 2 2), which is a list. This use of quotation marks is similar to written English, where we use quotation marks to indicate words and phrases that we don’t want interpreted in the usual way. LISP doesn’t mind you putting lists inside other lists:

(+ 2 (* 3 2))

The inside list tells LISP to multiply 3 and 2, which simplifies the list to:

(+ 2 6)

and this then evaluates to 8.
So LISP is easy!


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: