Hello,<br><br>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.<br>
<br>A test with my implementation:<br><br><span style="font-family: courier new,monospace;">cl-user> (macroexpand-1 '(whichever (list 1) (list 2) (list 3) (list 4) (list 5) (list 6) (list 7)))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">(let ((#:random-number854 (random 7)))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (if (< #:random-number854 3)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (if (< #:random-number854 1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (list 1)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (if (< #:random-number854 2)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (list 2)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (list 3)))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (if (< #:random-number854 5)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (if (< #:random-number854 4)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (list 4)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (list 5))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (if (< #:random-number854 6)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (list 6)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (list 7)))))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">t</span><br><br>Regards,<br>Gustavo Henrique Milaré.<br>