Contents

Lisp - Basic Facts


While the occasional user of Maxima does not need to know Lisp, a good understanding of that language is a necessity for those who want to analyse the code of Maxima and to add own code.

This document describes the fundamental properties of Lisp, it does not pay attention to the peculiarities of the currently available implementations.

(LENGTH <arg>)

This function answers the length of its argument, a list.

Definition

(LAMBDA (arg)
  (COND ((NULL arg) 0)
        (T (ADD1 (LENGTH (CDR arg))))
) )

Rules

(INTEGERP (LENGTH <arg>))
       TRUE
(LENGTH (LIST))
       0
(LENGTH (APPEND <a>  <b>))  
       (PLUS (LENGTH <a>) (LENGTH <b>))

(APPEND <a> <b>)

This function answers a new list that contains the top-level elements of <a> and <b>.

Definition:

(DEFFUN APPEND
   (LAMBDA (A B)
      (COND ((NULL A) B)
            (T (CONS (CAR A)
                     (APPEND (CDR A) B)
)  )  )     )  )

Rules:

(APPEND (APPEND <a>  <b>) <c>)
       (APPEND <a> (APPEND <b>  <b>))

(REVERSE <arg>)

This function answers a list that contains the top-level elements of the argument in reversed order.

Definition

(DEFFUN REVERSE
   (LAMBDA (A)
      (COND ((NULL A) NIL)
            (T (APPEND (REVERSE (CDR A))
                       (LIST (CAR A))
)  )  )     )  )

A tail-recursive definition uses an auxiliary function that takes two parameters: a restlist and the reversed list that is constructed so far:

(DEFFUN REVERSE
   (LAMBDA (A)
      ((LABEL RV
          (LAMBDA (rest result)
             (COND ((NULL rest) result)
                   (T (RV (CDR rest)
                          (CONS (CAR rest)
                                result
       )  )  )     )  )   )
       A
       NIL
)  )  )

Rules

(REVERSE (REVERSE <arg>))
       <arg>
(LENGTH (REVERSE <arg>))
       (LENGTH <arg>)
(REVERSE (APPEND <a>  <b>))  
       (APPEND (REVERSE <b>) (REVERSE <a>))

(MEMBER <arg> <list>)

This function checks whether <arg> is an top-level element of the list <list>.

Definition

(DEFFUN MEMBER
   (LAMBDA (A L)
      (COND ((NULL L) NIL)
            ((EQUAL A (CAR L)) B)
            (T (MEMBER A (CDR A)))
)  )  )

(PAIR <a> <a>)

This function checks whether <arg> is an top-level element of the list <list>.

Definition

(DEFFUN MEMBER
   (LAMBDA (A B)
      (COND ((OR (NULL A) (NULL B)) NIL)
            (T (CONS (CONS (CAR A) (CAR B))
                     (PAIR (CDR A) (CDR B))
            )  )
)  )  )

A tail-recursive Definiiton

(DEFFUN MEMBER
   (LAMBDA (A B)
      (COND ((OR (NULL A) (NULL B)) NIL)
            (T (CONS (CONS (CAR A) (CAR B))
                     (PAIR (CDR A) (CDR B))
            )  )
)  )  )


Contents