Hash :
9961ed5e
Author :
Thomas de Grivel
Date :
2022-11-18T19:40:00
(lessp ‘a ‘b) => T
(lessp ‘a “a”) => T
(lessp ‘(a b 1) ‘(a b 2)) => T
(defstruct fruit weight price)
(defmethod lessp ((a fruit) (b fruit)) (lessp (/ (fruit-price a) (fruit-weight a))
(/ (fruit-price b) (fruit-weight b))))
(let ((apple (make-fruit :price 0.3 :weight 100))
(orange (make-fruit) :price 4.5 :weight 1000))
(lessp apple orange))
=> T
This project welcomes LESSP methods for types that have an atomic type specifier, with an emphasis on speed and functional correctness.
To submit contributions, just fork the project and submit a pull request.
lessp - Generic order predicate
Copyright 2011-2022 Thomas de Grivel thodg@kmx.io
Permission is hereby granted to use this software granted the above copyright notice and this permission paragraph are included in all copies and substantial portions of this software.
THIS SOFTWARE IS PROVIDED “AS-IS” WITHOUT ANY GUARANTEE OF PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF THIS SOFTWARE.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
lessp - Generic order predicate
===============================
Compare anything
----------------
(lessp 'a 'b)
=> T
(lessp 'a "a")
=> T
(lessp '(a b 1) '(a b 2))
=> T
Your own order
--------------
(defstruct fruit weight price)
(defmethod lessp ((a fruit) (b fruit))
(lessp (/ (fruit-price a) (fruit-weight a))
(/ (fruit-price b) (fruit-weight b))))
(let ((apple (make-fruit :price 0.3 :weight 100))
(orange (make-fruit) :price 4.5 :weight 1000))
(lessp apple orange))
=> T
Contribute
----------
This project welcomes LESSP methods for types that have an
[atomic type specifier][1], with an emphasis on speed and functional
correctness.
[1]: http://www.lispworks.com/documentation/lw51/CLHS/Body/04_bc.htm
To submit contributions, just fork the project and submit a pull
request.
Licence
-------
lessp - Generic order predicate
Copyright 2011-2022 Thomas de Grivel <thodg@kmx.io>
Permission is hereby granted to use this software granted
the above copyright notice and this permission paragraph
are included in all copies and substantial portions of this
software.
THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
THIS SOFTWARE.