Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] Scanf: cannot see why "_" causes problems.

Expand Messages
  • Hugo Ferreira
    Thanks Chantal Keller and Eric Cooper for the correction.
    Message 1 of 4 , May 31 11:25 AM
    • 0 Attachment
      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 ;;
      >> Exception:
      >> Scanf.Scan_failure
      >> "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.
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.