Function: butlast

butlast is a byte-compiled function defined in subr.el.gz.

Signature

(butlast LIST &optional N)

Documentation

Return a copy of LIST with the last N elements removed.

If N is omitted or nil, return a copy of LIST without its last element. If N is zero or negative, return LIST.

Other relevant functions are documented in the list group.

View in manual

Probably introduced at or before Emacs version 21.1.

Shortdoc

;; list
(butlast '(one two three))
    => (one two)

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun butlast (list &optional n)
  "Return a copy of LIST with the last N elements removed.
If N is omitted or nil, return a copy of LIST without its last element.
If N is zero or negative, return LIST."
  (declare (side-effect-free t))
  (unless n
    (setq n 1))
  (if (<= n 0)
      list
    (take (- (length list) n) list)))