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:<br><br><span style="font-family: courier new,monospace;">COMMON-LISP-USER></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">(cl-utilities:extrema '((1 2 3) (1 2) (1 3) (2 3) (2 3 4)) #'subsetp)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">((1 2) (1 3) (2 3) (2 3 4))</span><br><br><br>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.<br>
<br>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:<br><br><span style="font-family: courier new,monospace;">(defun extremals (seq pred)</span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (loop for member on seq</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for elt = (car member)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> unless (or (find-if (rcurry pred elt)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (cdr member))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (find-if (f_ (and (not (eq _ elt))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (funcall pred _ elt)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> befores))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> collect elt</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> and collect elt into befores))</span><br><br>Where<br><br><span style="font-family: courier new,monospace;">(defmacro f_ (&body body)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> `(function (lambda (_) ,@body)))</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(defun rcurry (function &rest args)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (f_ (apply function _ args)))</span><br><br>Actually I found that really interesting specially to comparing types. E.g., if you are dealing with the "and" type specifier, e.g.:<br>
<br><span style="font-family: courier new,monospace;">(and integer fixnum)</span><br><br>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<br>
<br><span style="font-family: courier new,monospace;">(if (eq (car type-spec) 'and)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (cons 'and (extremals (cdr type-spec) #'subtypep)))</span><br>
<br>Does the job (and looks quite pretty lisp code :)<br><br>Be free to use this code, but just if you want to. I, Gustavo, put it under public domain.<br>