Function: P-LAST

Documentation

Returns the last persistent cons cell of a persistent list (or NIL if the list is empty).

Source

(defun p-last (list &optional (n 1))
  "Returns the last persistent cons cell of a persistent list (or
NIL if the list is empty)."
  (unless (= n 1)
    ;; DO: Implement this case.
    (error "The optional argument for P-LAST isn't implemented yet."))
  (let ((result list)
        (tail (p-cdr list)))
    (loop until (p-endp tail)
          do (shiftf result tail (p-cdr tail)))
    result))
Source Context