Return character to stdin in Ocaml

Is there a C ++ method equivalent istream::putback(char)for OCaml?

How can I add a character to the beginning of stdin?

+3
source share
3 answers

You cannot do this with in_channelor with Stream.t. Here are some suggestions:

  • If you return the character you read, you can use use peekto check the stream instead of deleting the element.

  • You may be able to write the C interface directly for this function. I see that this is a very bad idea.

  • Have you considered using the battery instead?

  • , - , .

+3

OCaml, , . . , , .

+2

: . ( Extlib) -, .

, , , Extlib, , bu - Enum (BatEnum ). Enum " " . , stdin char Enum.t, Enum.next, Enum.push .

Perhaps then re-wrapping such an enumeration will be IO ( BatIO ) for a more flexible interface, if you first checked that these modules do not perform internal buffering, which would ruin the semantics of character clicks.

+1
source

Source: https://habr.com/ru/post/1704473/


All Articles