X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Flist.lisp;h=6b58aae4f3614be25ac44a5d007b24a7be6215f3;hb=21d052d84e68ca27e1815d2c8a9484da8f7beb7a;hp=a41d821220c39f2afdd5911a59f65766b8010d0b;hpb=c6d504316367c4709e066f58d5593216b150ee5e;p=jscl.git diff --git a/src/list.lisp b/src/list.lisp index a41d821..6b58aae 100644 --- a/src/list.lisp +++ b/src/list.lisp @@ -68,6 +68,16 @@ (defun nth (n list) (car (nthcdr n list))) +(define-setf-expander nth (n list) + (let ((g!list (gensym)) + (g!index (gensym)) + (g!value (gensym))) + (values (list g!list g!index) + (list list n) + (list g!value) + `(rplaca (nthcdr ,g!index ,g!list) ,g!value) + `(nth ,g!index ,g!list)))) + (defun caar (x) (car (car x))) (defun cadr (x) (car (cdr x))) (defun cdar (x) (cdr (car x))) @@ -208,16 +218,19 @@ (setq list (cdr list)))) -(defun assoc (x alist &key (test #'eql)) +(defun assoc (x alist &key key (test #'eql testp) (test-not #'eql test-not-p)) (while alist - (if (funcall test x (caar alist)) + (if (satisfies-test-p x (caar alist) :key key :test test :testp testp + :test-not test-not :test-not-p test-not-p) (return) (setq alist (cdr alist)))) (car alist)) -(defun rassoc (x alist &key (test #'eql)) +(defun rassoc (x alist &key key (test #'eql) (test #'eql testp) + (test-not #'eql test-not-p)) (while alist - (if (funcall test x (cdar alist)) + (if (satisfies-test-p x (cdar alist) :key key :test test :testp testp + :test-not test-not :test-not-p test-not-p) (return) (setq alist (cdr alist)))) (car alist)) @@ -256,7 +269,7 @@ (list x) (list new-value) `(progn (rplacd ,cons ,new-value) ,new-value) - `(car ,cons)))) + `(cdr ,cons)))) ;; The NCONC function is based on the SBCL's one.