The cl-utilities library contains one function which cannot be found in alexandria that necessity pops up every now and then:
Returning the maximum (or minimum) element in a sequence with respect to an arbitrary calculation involving the elements.
I.e.
(elt (sort (copy-sequence <SEQUENCE>) #'< :key <FUNCTION>) 0) ; or #'>
except doing it more efficiently.
CL-UTILITIES calls this function EXTREMUM. (It also provides a couple of more functions along the lines to cover some edge cases.)
The code can be found here:
http://common-lisp.net/viewvc/cl-utilities/cl-utilities/extremum.lisp?rev ision=1.10&view=markup
As the code is Public Domain, it could just be moved as is.
I find no other use of cl-utilities and would like to see it become entirely obsolete.
T
On 25 April 2012 12:15, Tobias C Rittweiler tcr@freebits.de wrote:
The cl-utilities library contains one function which cannot be found in alexandria that necessity pops up every now and then:
Returning the maximum (or minimum) element in a sequence with respect to an arbitrary calculation involving the elements.
I.e.
(elt (sort (copy-sequence <SEQUENCE>) #'< :key <FUNCTION>) 0) ; or #'>
except doing it more efficiently.
CL-UTILITIES calls this function EXTREMUM. (It also provides a couple of more functions along the lines to cover some edge cases.)
Pushed a version. Can you verify that it is what you wanted, and performs acceptably?
Cheers,
-- Nikodemus
On 25 April 2012 15:30, Nikodemus Siivola nikodemus@random-state.net wrote:
CL-UTILITIES calls this function EXTREMUM. (It also provides a couple of more functions along the lines to cover some edge cases.)
Pushed a version. Can you verify that it is what you wanted, and performs acceptably?
So, what about the NO-EXTREMUM thing?
I think it's good that the behaviour specified, instead of depending on the PREDICATE and REDUCE, but an an interface NO-EXTREMUM + CONTINUE is terrible: unless you handle the error right around the call site, it's pointless, since no-one higher up the call stack can know for sure where the error came from. At the call site it is overly verbose and inefficient:
(handler-bind ((no-extremum #'continue)) (extremum ...))
I would much like to remove mention of the restart from the docstring, and add &KEY DEFAULT instead:
(extremum ... :default nil)
would provide the same behaviour as invoking CONTINUE. Since you obviously actually use this thing, any comments?
Cheers,
-- Nikodemus
In article CADow0CrM=mrumUUTe11ZxgT594Sz41PApPYg--y+SBb8jzqOXQ@mail.gmail.com, Nikodemus Siivola nikodemus@random-state.net wrote:
On 25 April 2012 15:30, Nikodemus Siivola nikodemus@random-state.net wrote:
CL-UTILITIES calls this function EXTREMUM. (It also provides a couple of more functions along the lines to cover some edge cases.)
Pushed a version. Can you verify that it is what you wanted, and performs acceptably?
So, what about the NO-EXTREMUM thing?
I think it's good that the behaviour specified, instead of depending on the PREDICATE and REDUCE, but an an interface NO-EXTREMUM + CONTINUE is terrible: unless you handle the error right around the call site, it's pointless, since no-one higher up the call stack can know for sure where the error came from. At the call site it is overly verbose and inefficient:
(handler-bind ((no-extremum #'continue)) (extremum ...))
I would much like to remove mention of the restart from the docstring, and add &KEY DEFAULT instead:
(extremum ... :default nil)
would provide the same behaviour as invoking CONTINUE. Since you obviously actually use this thing, any comments?
I agree it's pointless. Why not just return NIL? (Or possibly (values <element> T) in case an extremum was found.) FIND, FIND-IF just return NIL, too, never minding the ambiguity. And EXTREMUM can be thought of a special case of FIND.
T
alexandria-devel@common-lisp.net