;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; text-menu.lisp ;; A simple tool for presenting options to the user of a Lisp program. ;; Lee Spector, October 16, 1997 ;; example: (text-menu '(fish (frogs and pickles) typewriters)) (defun text-menu (items) "Prints the provided items (which should be in a list) with a number for each and prompts the user to choose one by typing a number. Returns the chosen item. Doesn't check that the user's input is reasonable; unreasonable inputs will cause errors." ;; print the initial instructions (format t "~%Choose one of the following by typing a number:") ;; print the numbers and items (dotimes (item-number (length items)) (format t "~%~A: ~A" (+ item-number 1) (nth item-number items))) ;; prompt for the choice (format t "~%Choice: ") ;; read the user's choice and return the chosen item (nth (- (read) 1) items))