Hello,
I have optimized the expansion of the macro whichever. In the current implementation, it generates n random values, creates O(n) functions and calls one of them. Using a sort of "inline" binary search, I was able to create an expansion which makes one call to RANDOM, O(log n) tests, and also does not create any extra function.
A test with my implementation:
cl-user> (macroexpand-1 '(whichever (list 1) (list 2) (list 3) (list 4) (list 5) (list 6) (list 7)))
(let ((#:random-number854 (random 7)))
(if (< #:random-number854 3)
(if (< #:random-number854 1)
(list 1)
(if (< #:random-number854 2)
(list 2)
(list 3)))
(if (< #:random-number854 5)
(if (< #:random-number854 4)
(list 4)
(list 5))
(if (< #:random-number854 6)
(list 6)
(list 7)))))
t
Regards,
Gustavo Henrique Milaré.