From 098e9c31d5a58cabde2cd8e15aa4914d44ed2321 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 28 Dec 2020 20:27:14 -0800 Subject: 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. --- share/txr/stdlib/quips.tl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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%)) -- cgit v1.2.3