From 86d7aafea65e8048c56bdf5c81bf9c7a7f095022 Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Thu, 30 Jul 2026 20:37:17 +0100 Subject: Add conditional start so code can be loaded in repl --- mathslap-rec/mathslap-rec.clisp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'mathslap-rec') diff --git a/mathslap-rec/mathslap-rec.clisp b/mathslap-rec/mathslap-rec.clisp index 86d607b..121d62d 100644 --- a/mathslap-rec/mathslap-rec.clisp +++ b/mathslap-rec/mathslap-rec.clisp @@ -3,9 +3,6 @@ ;;;; This version uses a recursive loop instead of LOOP. ;;;; concise instructions -(print "MathSlap") -(print "Hit Enter for another number. q and Enter to quit.") - (setq *random-state* (make-random-state t)) ;;;; Generate a random number for our game. Avoid having to write the @@ -36,6 +33,16 @@ ;;;; Initiate the recursion ;; Use a LET* form for local variables, with defined variables depending on each other. -(let* ((starting-numbers (list (have-number) (have-number))) - (starting-prompt (format nil "MathSlap ~{~a ~}" starting-numbers))) - (recloop starting-prompt nil)) + +(defun run-game () + (print "MathSlap") + (print "Hit Enter for another number. q and Enter to quit.") + + (let* ((starting-numbers (list (have-number) (have-number))) + (starting-prompt (format nil "MathSlap ~{~a ~}" starting-numbers))) + (recloop starting-prompt nil))) + + +;;;; Run the game right away when loaded as a script +(when (interactive-stream-p *standard-input*) + (run-game)) -- cgit v1.2.3