Re: "ocaml_beginners":: Scanf: cannot see why "_" causes problems.
- Thanks Chantal Keller and Eric Cooper for the correction.
Eric Cooper wrote:
> On Mon, May 31, 2010 at 05:03:13PM +0100, Hugo Ferreira wrote:
>> I have tried to use the Scanf module to parse a simple string
>> as follows:
>> # let file_id _ _ _ = true ;;
>> val file_id : 'a -> 'b -> 'c -> bool = <fun>
>> # Scanf.sscanf "0_8_72_tset" "%d_%d%s" file_id ;;
>> "scanf: bad input at char number 7: looking for '_', found 't'".
>> I cannot understand why the "_" is problematic.
> OCaml allows underscores in integer constants. They were introduced
> to make constants more readable (the way one would use ',' or '.'
> depending on locale):
> # 1_000_000;;
> - : int = 1000000
> But there's no restriction on where they occur:
> # 1_0_00;;
> - : int = 1000
> # 1_0;;
> - : int = 10
> So sscanf parses the 0_8_72 as your first integer.