next up previous
Contents Next: car (FUNCTION) Up: Appendix: Selected LISP Previous: atom (PREDICATE)

butlast (FUNCTION)

Format: (butlast <list>) (butlast <list> <int>)

Required arguments: 1

First argument must evaluate to a list

Optional arguments: 1

<int> must evaluate to an integer

If butlast is used with a single argument then it is equivalent to (reverse (rest (reverse <list>))). I.e. it will return the list argument with the last element removed.

If butlast is given an integer second argument, it is equivalent to (reverse (nthcdr <num> (reverse <list>))). I.e. it will remove the number of elements specified from the end of the list.


>(butlast '(a s d f))
(A S D)

>(butlast '(a s d f) 2)
(A S)

>(butlast '(a s d f) 0)
(A S D F)

>(reverse (nthcdr 2 (reverse '(a s d f))))
(A S)

© Colin Allen & Maneesh Dhagat
November 1999