Tail recursive implementation of read-file-lines.
(read-file-lines-aux line lines channel state) returns
Function:
(defun read-file-lines-aux (line lines channel state) (declare (xargs :guard (and (character-listp line) (string-listp lines) (symbolp channel) (open-input-channel-p channel :byte state)) :stobjs state)) (b* (((unless (mbt (state-p state))) (mv lines state)) ((mv byte state) (read-byte$ channel state)) ((unless byte) (let ((lines (cons (str::rchars-to-string line) lines))) (mv lines state))) ((the character char) (code-char (the (unsigned-byte 8) byte))) (line (cons char line)) ((when (eql char #\Newline)) (let ((lines (cons (str::rchars-to-string line) lines))) (read-file-lines-aux nil lines channel state)))) (read-file-lines-aux line lines channel state)))
Theorem:
(defthm state-p1-of-read-file-lines-aux (implies (and (force (state-p1 state)) (force (symbolp channel)) (force (open-input-channel-p1 channel :byte state))) (b* (((mv ?lines state) (read-file-lines-aux line lines channel state))) (state-p1 state))))
Theorem:
(defthm open-input-channel-p1-of-read-file-lines-aux (implies (and (force (state-p1 state)) (force (symbolp channel)) (force (open-input-channel-p1 channel :byte state))) (b* (((mv ?lines state) (read-file-lines-aux line lines channel state))) (open-input-channel-p1 channel :byte state))))
Theorem:
(defthm string-listp-of-read-file-lines-aux (implies (force (string-listp lines)) (string-listp (mv-nth 0 (read-file-lines-aux line lines channel state)))))
Theorem:
(defthm true-listp-of-read-file-lines-aux (equal (true-listp (mv-nth 0 (read-file-lines-aux line lines channel state))) (true-listp lines)))