From gugamilare at gmail.com Wed Mar 12 01:43:28 2008 From: gugamilare at gmail.com (Gustavo) Date: Tue, 11 Mar 2008 22:43:28 -0300 Subject: [cl-utilities-devel] Another extremum concept Message-ID: <4be8713d0803111843q28728bib88163e51e54be41@mail.gmail.com> One I made a function that I needed that looks like the idea of extrema. I saw it and tested to see if it did what I thought: COMMON-LISP-USER> (cl-utilities:extrema '((1 2 3) (1 2) (1 3) (2 3) (2 3 4)) #'subsetp) ((1 2) (1 3) (2 3) (2 3 4)) And realized that it doesn't. It returns (2 3 4), and I was assuming that it wouldn't because (2 4) is strictly smaller (in subset sense). Then I took a look at the code and realized that it is supposed to do something different from what I was expecting. The given order is assumed to "total" (given a equivalence), not "partial" as I thought. In partial order, two elements a, b that neither a < b and b < a are not assumed equal or equivalent. Anyway, the function I did (renaming to extremals to be consistent to the notation, but initially it was named minimals), tested to many cases, is this: (defun extremals (seq pred) (loop for member on seq for elt = (car member) unless (or (find-if (rcurry pred elt) (cdr member)) (find-if (f_ (and (not (eq _ elt)) (funcall pred _ elt))) befores)) collect elt and collect elt into befores)) Where (defmacro f_ (&body body) `(function (lambda (_) , at body))) (defun rcurry (function &rest args) (f_ (apply function _ args))) Actually I found that really interesting specially to comparing types. E.g., if you are dealing with the "and" type specifier, e.g.: (and integer fixnum) You might want to remove every type that is more complex such that, in this case, only the fixnum remains. In this case, something like (if (eq (car type-spec) 'and) (cons 'and (extremals (cdr type-spec) #'subtypep))) Does the job (and looks quite pretty lisp code :) Be free to use this code, but just if you want to. I, Gustavo, put it under public domain. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tayloj at cs.rpi.edu Wed Mar 12 19:32:01 2008 From: tayloj at cs.rpi.edu (Taylor, Joshua) Date: Wed, 12 Mar 2008 15:32:01 -0400 Subject: [cl-utilities-devel] CL-Utilities Manual Message-ID: <1c3ea73c0803121232y995f513wa08f037cc12e4c28@mail.gmail.com> Hello, (I hope this is the right place to mention this. I didn't see a mailing list specifically for the manual...) I've been taking a look at the cl-utilities manual, and came across the following example on the page for collecting [http://common-lisp.net/project/cl-utilities/doc/collecting.html]: (multiple-value-bind (a b) (with-collectors (x y) (x 1) (y 2) (x 3)) (append a b)) => (1 2 3) Running the code actually generates (1 3 2). Great package though, I wish I'd found it earlier in my lisping. -- ===================== Joshua Taylor tayloj at cs.rpi.edu, jtaylor at alum.rpi.edu "A lot of good things went down one time, back in the goodle days." John Hartford