Lookahead-* procedures mutate port position.

Issue #184 resolved
Takashi Kato repo owner created an issue

This should return (#\a 0 #\b) but (#\a 1 #\a)

(define in (open-string-input-port "ab"))

(let* ((c0 (peek-char in))
       (pos (port-position in))
       (c1 (begin
             (set-port-position! in 1)
             (read-char in))))
  (list c0 pos c1))

Comments (3)

  1. Takashi Kato reporter

    It turned out that both binary and textual ports peeked port position handling is incorrect. The following script shows wrong results:

    #!r6rs
    (import (rnrs))
    
    (define (print . args) (for-each display args) (newline))
    
    (define (test-port in peek read)
      (print
       (let* ((c0 (peek in))
              (pos (port-position in))
              (c1 (begin
                    (set-port-position! in 1)
                    (read in))))
         (list c0 pos c1)) ))
    (test-port (open-string-input-port "ab") peek-char read-char)
    (test-port (open-bytevector-input-port #vu8(1 2)) lookahead-u8 get-u8)
    
  2. Log in to comment