From 78b62107690123d8d7a1a400e4a1d744408a05b1 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Fri, 10 Sep 2004 09:02:03 +0000 Subject: [PATCH] r9992: new function --- datetime.lisp | 2 +- lists.lisp | 7 +++++++ package.lisp | 3 ++- tests.lisp | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/datetime.lisp b/datetime.lisp index 52d45b2..f8aca20 100644 --- a/datetime.lisp +++ b/datetime.lisp @@ -89,7 +89,7 @@ (10 . "October") (11 . "November") (12 . "December"))) - + (defun monthname (stream arg colon-p at-p &optional width (mincol 0) (colinc 1) (minpad 0) (padchar #\Space)) "Print the name of the month (1=January) corresponding to ARG on STREAM. This is intended for embedding in a FORMAT directive: WIDTH governs the number of characters of text printed, MINCOL, COLINC, MINPAD, PADCHAR work as for ~A" (let ((monthstring (cdr (assoc arg *monthnames*)))) diff --git a/lists.lisp b/lists.lisp index 9793f27..c18fe7e 100644 --- a/lists.lisp +++ b/lists.lisp @@ -192,3 +192,10 @@ (setf ,plist (append ,plist (list ,pkey ,value))))))) +(defun unique-slot-values (list slot &key (test 'eql)) + (let ((uniq '())) + (dolist (item list (nreverse uniq)) + (let ((value (slot-value item slot))) + (unless (find value uniq :test test) + (push value uniq)))))) + diff --git a/package.lisp b/package.lisp index 9b9316f..fe5e7a4 100644 --- a/package.lisp +++ b/package.lisp @@ -135,7 +135,8 @@ #:update-plist #:get-plist #:flatten - + #:unique-slot-values + ;; seq.lisp #:nsubseq diff --git a/tests.lisp b/tests.lisp index 86e86bd..b555555 100644 --- a/tests.lisp +++ b/tests.lisp @@ -379,6 +379,25 @@ (make-url "pg" :anchor "then" :vars '(("a" . "5") ("b" . "pi"))) "pg?a=5&b=pi#then") +(defclass test-unique () + ((a :initarg :a) + (b :initarg :b))) + + +(deftest :unique.1 + (let ((list (list (make-instance 'test-unique :a 1 :b 1) + (make-instance 'test-unique :a 2 :b 2) + (make-instance 'test-unique :a 3 :b 2)))) + (values + (unique-slot-values list 'a) + (unique-slot-values list 'b))) + (1 2 3) (1 2)) + +(deftest :unique.2 + (unique-slot-values nil 'a) + nil) + + ;;; MOP Testing ;; Disable attrib class until understand changes in sbcl/cmucl -- 2.34.1