I'm looking for something like input_char stdin
but without waiting for a return key. I would not to depend on a big dependency like lambda-term.
Regarding the :: symbol - as already mentioned, it is used to create lists from a single element and a list ( 1::[2;3] creates a list [1;2;3] ).
The |> operator represents reverse function application.
OCaml doesn't have a return keyword — the last expression in a function becomes the result of the function automatically.
The type 'a is a type variable, and stands for any given type. The reason why sort can apply to lists of any type is that the comparisons (=, <=, etc.) are polymorphic in OCaml: they operate between any two values of the same type. This makes sort itself polymorphic over all list types.
Handling input in full lines is easy. Handling it a character at a time is a little bit system dependent. If you're on a Unix-like system you should be able to do this using the Unix
module:
let get1char () =
let termio = Unix.tcgetattr Unix.stdin in
let () =
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN
{ termio with Unix.c_icanon = false } in
let res = input_char stdin in
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio;
res
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With