Menu

#139 peek_char/1 is broken when reading from atom

wrong answer
closed-fixed
nobody
5
2006-05-22
2006-05-20
No

peek_char/1 doesn't just peek, but actually consumes
characters when reading from a stream. For instance:

?- open(atom('abc'), read, IO), see(IO),
get0(C1), peek_char(_), get0(C2),
atom_codes(A,[C1,C2]), writeln(A),
seen, close(IO).

prints `ac' and 'b' is missing.

I am quite certain that this was not the case with the
old file_read/2 when it was reading from a string.

Discussion

  • David S. Warren

    David S. Warren - 2006-05-22
    • status: open --> open-fixed
     
  • David S. Warren

    David S. Warren - 2006-05-22

    Logged In: YES
    user_id=13069

    Yes, strgetc was incorrectly being used to get the next
    character. I've introduced a macro strpeekc to return the
    next character but not advance the pointer. Your example
    now works.
    -David

     
  • David S. Warren

    David S. Warren - 2006-05-22

    Logged In: YES
    user_id=13069

    (Forgot to close it...)

     
  • David S. Warren

    David S. Warren - 2006-05-22
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.