diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-12-28 20:27:14 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-12-28 20:27:14 -0800 |
commit | b800805b369a44bd5eb7bd51f02dd8c9dbbe009b (patch) | |
tree | d3d0a2da48b4ba72beb856676aea2eb5ab1b0198 | |
parent | 366c11949a49351b154f45bee92c7d49b402d5d0 (diff) | |
download | txr-b800805b369a44bd5eb7bd51f02dd8c9dbbe009b.tar.gz txr-b800805b369a44bd5eb7bd51f02dd8c9dbbe009b.tar.bz2 txr-b800805b369a44bd5eb7bd51f02dd8c9dbbe009b.zip |
quip: function cycles through all quips.
* share/txr/stdlib/quips.tl (sys:%shuffled-quips%): New variable.
(quip): Pop quips from the new variable. When the list is empty,
populate it by shuffling the quips.
-rw-r--r-- | share/txr/stdlib/quips.tl | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/share/txr/stdlib/quips.tl b/share/txr/stdlib/quips.tl index c509e981..89b01b72 100644 --- a/share/txr/stdlib/quips.tl +++ b/share/txr/stdlib/quips.tl @@ -79,5 +79,10 @@ (defparml sys:%quip-rand-state% (make-random-state)) +(defvarl sys:%shuffled-quips%) + (defun quip () - [sys:%quips% (rand (len sys:%quips%) sys:%quip-rand-state%)]) + (unless sys:%shuffled-quips% + (let ((*random-state* sys:%quip-rand-state%)) + (set sys:%shuffled-quips% (shuffle sys:%quips%)))) + (pop sys:%shuffled-quips%)) |