Skip to content
Snippets Groups Projects
Commit cad3d94e authored by ram's avatar ram
Browse files

Added the LAST-N X3j13 cleanup which gives LAST an optional arg for the number

of last conses to return.  Added the TAILP-NIL cleanup with clarifies the
behavior of TAILP when the first arg is atomic.
parent 82b58924
No related branches found
No related tags found
No related merge requests found
...@@ -175,11 +175,16 @@ ...@@ -175,11 +175,16 @@
(result list (cdr result))) (result list (cdr result)))
((not (plusp i)) result))) ((not (plusp i)) result)))
(defun last (list) (defun last (list &optional (n 1))
"Returns the last cons (not the last element!) of a list." "Returns the last N conses (not the last element!) of a list."
(do ((list list (cdr list)) (declare (type index n))
(result nil list)) (do ((checked-list list (cdr checked-list))
((null list) result))) (returned-list list)
(index 0 (1+ index)))
((atom checked-list) returned-list)
(declare (type index index))
(if (>= index n)
(pop returned-list))))
(defun list (&rest args) (defun list (&rest args)
"Returns constructs and returns a list of its arguments." "Returns constructs and returns a list of its arguments."
...@@ -596,10 +601,12 @@ ...@@ -596,10 +601,12 @@
(return list))))) (return list)))))
(defun tailp (sublist list) (defun tailp (sublist list)
"Returns T if sublist is one of the cons'es in list" "Returns T if (EQL Sublist (NTHCDR <n> List)) for some value of <n>, NIL
(do ((x list (cdr x))) otherwise."
((endp x) '()) (do ((list list (cdr list)))
(if (eq x sublist) (return T)))) ((atom list) (eql list sublist))
(if (eql sublist list)
(return t))))
(defun adjoin (item list &key (key #'identity) (test #'eql) (test-not nil notp)) (defun adjoin (item list &key (key #'identity) (test #'eql) (test-not nil notp))
"Add item to list unless it is already a member" "Add item to list unless it is already a member"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment