I have been meaning to learn LISP and for a small task I wanted to find out the sum of all integers on STDIN. So for
> clisp a.lisp 1 2 3^D 6
My code is as follows. I have a small helper function, my core function and the invocation of it.
(defun read-int() (parse-integer (read-line))) (defun sum-stdin() (handler-case ; recurse (+ (read-int) (sum-stdin)) ; base case: if eof (error(c) (values 0)))) (write (sum-stdin))
Is this according to "the lisp way"?
One thing I see is that it feels weird to basically have the base case of my recursive function what would otherwise be the catch block in a non-functional language. I don't think there is a rule against it, but it just seems very unusual and hacky.