Implement a program that reads some integers then prints their sum

Allows junk, and doesn't crash horribly.
This commit is contained in:
2025-02-09 12:36:40 +00:00
parent 4977b427d8
commit bd47029bd8

View File

@@ -25,6 +25,19 @@
(force-output) (force-output)
(read-line)) (read-line))
(defun read-integers ()
(->> (read-input "Enter numbers: ")
(uiop:split-string)
(mapcar (lambda (s) (parse-integer s :junk-allowed t)))
(remove-if #'null)))
(defun read-until-integers ()
(let ((inp (read-integers)))
(while (null inp)
(format t "Need at least one integer...~%")
(setq inp (read-integers)))
inp))
(defun start () (defun start ()
(->> (read-input "Enter name: ") (--> (read-until-integers)
(format t "Hello, ~a!~%"))) (format t "~a = ~a~%" (cons '+ _) (reduce #'+ _))))