Read one character from an open
NOTE: We generally prefer to avoid read-char$. It is easy to use read-byte$ instead, which is generally more efficient and avoids certain character-encoding issues; see below for details.
Signature: (read-char$ channel state-state) returns
This is a logic-mode function, but its logical definition is tricky; see logical-story-of-io. The main logical consequence is the updating of state.
Under the hood, we read a
In some sense, it is redundant for ACL2 to have separate kinds of input
channels for characters and bytes. After all, ACL2 has exactly 256 characters corresponding to bytes 0-255, and provides functions like char-code and code-char for converting between these characters and
bytes. So, one could easily define
That being said, we generally prefer to use byte input. Common Lisp
implementations have some freedom in how they implement characters. Because of
this, and because different Lisps might try to use different encodings when
reading files, ACL2's
On the other hand, there is no equivalent of
Theorem:
(defthm state-p1-of-read-char$ (implies (and (state-p1 state) (symbolp channel) (open-input-channel-p1 channel :character state)) (state-p1 (mv-nth 1 (read-char$ channel state)))))
Theorem:
(defthm open-input-channel-p1-of-read-char$ (implies (and (state-p1 state) (open-input-channel-p1 channel :character state)) (open-input-channel-p1 channel :character (mv-nth 1 (read-char$ channel state)))))
Theorem:
(defthm characterp-of-read-char$ (implies (and (mv-nth 0 (read-char$ channel state)) (state-p1 state) (open-input-channel-p1 channel :character state)) (characterp (mv-nth 0 (read-char$ channel state)))) :rule-classes (:rewrite (:type-prescription :corollary (implies (and (state-p1 state) (open-input-channel-p1 channel :character state)) (or (characterp (mv-nth 0 (read-char$ channel state))) (null (mv-nth 0 (read-char$ channel state))))))))
Theorem:
(defthm state-preserved-by-read-char$-when-eof (implies (and (not (mv-nth 0 (read-char$ channel state))) (state-p1 state) (open-input-channel-p1 channel :character state)) (equal (mv-nth 1 (read-char$ channel state)) state)))