bumble.sf.net language and parsing

plain text

The lisp Booklet

This booklet is about the Common Lisp programming language and in particular, the gcl implementation of that. Lisp is a 'list processing language'.

In lisp braces define a list. The first element of the list is often a function. Lisp is the macro language of the 'emacs' unix text editor.

@@ http://www.gigamonkeys.com/book/ an introductory book about common lisp

* evaluate 2 + 3 using the '+' function

 (+ 2 3)

* define a new lisp function

 (defun hello-world () (format t "hello, world"))

* call the 'hello-world' function

 (hello-world)

* load lisp code contained in the file 'hello.lisp'

 (load "hello.lisp")

* create a list of numbers (the list is returned by this function)

 (list 1 2 3)

Note the similarity of this with the tcl list command (which, no doubt was inspired by lisp)

* create a type of associative array (or 'plist')

 (list :a 1 :b 2 :c 3)

The colon character is important here.

* return the element associated with the ':a' element

 (getf (list :a 1 :b 2 :c 3) :a)

* a function which creates a basic data record using a plist

(defun make-cd (title artist rating ripped) (list :title title :artist artist :rating rating :ripped ripped)) ,,,

* make one record using the above function

 (make-cd "Roses" "Kathy Mattea" 7 t)

* create an empty global variable '*db*'

 (defvar *db* nil)

The *s are a naming convention for global variables

* a function to add an element to a global list variable

 (defun add-record (cd) (push cd *db*))

* a function to read a value from the user

(defun prompt-read (prompt) (format *query-io* "~a: " prompt) (force-output *query-io*) (read-line *query-io*)) ,,,

* if clause in lisp is known as a 'special operator'

 (if x (format t "yes") (format t "no"))