Comparable (Rankable / Sortable) enums in Common Lisp

Viewed 141

I wonder if there's any trick or library to get rankable enums in Common Lisp.

In general I define a set of enums like this

(deftype weekdays()
    '(member :sunday :monday :tuesday :wednesday :thursday :friday :saturday))

Surely I can compare two variables for containing the same weekday, e.g. if both contain :wednesday.

But I want to compare two different weekdays like "Is :thursday later than :monday"? That brings me back to constants

(defconstant +sunday+ 0)
(defconstant +monday+ 1)
and so on...

but that seems to be bad style.

What is best practice for doing this?

1 Answers
Related