is there an equivalent to the C++ method istream::putback(char)
for OCaml?
How could I add a character to the beginning of stdin?
You cannot do it with an in_channel
or with Stream.t
. Here are some suggestions:
If you are putting back a character you had read, you might want to use use peek
to examine the stream instead of removing the element.
You might have some luck writing a C-Interface to that function directly. I can see this being a really bad idea.
Have you considered using an accumulator instead?
Write a module around the current functions with a type that is a zipper or stack or some other structure that allows pushing characters back.