summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-12-28 20:27:14 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-12-28 20:27:14 -0800
commit098e9c31d5a58cabde2cd8e15aa4914d44ed2321 (patch)
treed3d0a2da48b4ba72beb856676aea2eb5ab1b0198 /share
parent5950fd90c38cef11347578a2bb89a31349f5eefc (diff)
downloadtxr-098e9c31d5a58cabde2cd8e15aa4914d44ed2321.tar.gz
txr-098e9c31d5a58cabde2cd8e15aa4914d44ed2321.tar.bz2
txr-098e9c31d5a58cabde2cd8e15aa4914d44ed2321.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.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/quips.tl7
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%))