Lisp - List Processing (or Lots of Irritating Superfluous Parenthesis)

Table of Contents

Documents

1. Checking equality

The four functions for checking equality are EQ EQL EQUAL EQUALP

1.1. EQ

This checks for object identity and cannot be used on numbers or characters. Don't use this - just use EQL instead

1.2. EQL

This checks if two objects of the same class are equal. This behaves just like EQ except that two objects of the same class with the same value are considered equal.

The following code is always false because the types of the objects are different:

CL-USER> (eql 1 1.0)
NIL

1.3. EQUAL

Can compare if different objects are identical. It will treat two lists with identical contents as being equal.

CL-USER> (eql (list 1 2 3) (list 1 2 3))
NIL
CL-USER> (equal (list 1 2 3) (list 1 2 3))
T
CL-USER> (eql "Hi there" "Hi there")
NIL
CL-USER> (equal "Hi there" "Hi there")
T

equal also considers strings with the same text as equal.

CL-USER> (equal "Hi there" "Hi there")
T

1.4. EQUALP

equalp considers strings with only differing case to be equal. equalp considers numbers equal if they represent the same value.

CL-USER> (equal "Hi There" "Hi there")
NIL
CL-USER> (equalp "Hi There" "Hi there")
T
CL-USER> (equal 1 1.0)
NIL
CL-USER> (equalp 1 1.0)
T

2. Style

2.1. Comments

Comments should be prefaced with one to four semicolons depending on what the comments apply to

;;;; File header comment goes here

;;; Paragraph comment which describes
;;; A major chunk of code that follows

(defun myfunc (params)
  (if (params)
      ;; This comment applies to the code that 
      ;; follows inside the function
      (call-some-function)
      (do-something-else) ; Comment just for this line
      (commit-stuff)))

3. Short forms

(function foo) is the same as #'foo

(quote foo) is the same as 'foo

4. References

Author: Bernt Hansen