```common lisp
;;;; TRE environment
;;;; Copyright (c) 2008 Sven Klose <pixel@copei.de>

(defun read-integer (&optional (str *standard-input*))
  (with (rec	#'(()
				    (if (digit-char-p (peek-char str))
						(+ (- #\0 (read-char str)) (rec))
						   0)))
	  (when (digit-char-p (peek-char str))
		(rec))))
```

Test on end of stream.
user
```common lisp
;;;; TRE environment
;;;; Copyright (c) 2008 Sven Klose <pixel@copei.de>

(defun read-integer (&optional (str *standard-input*))
  "Read positive integer from stream."
  (with (rec #'((v)
			      (if (awhen (peek-char str)
						(digit-char-p !))
					  (rec (+ (- (read-char str) #\0)
							  (* v 10)))
					  v)))
	(when (awhen (peek-char str)
		    (digit-char-p !))
	  (integer (rec 0)))))
```
assistant