Reputation: 1463
Can anyone explain this OCaml toplevel behaviour?
# 1________________________________1;;
- : int = 11
(The big line is a sequence of underscores: '_')
Out of curiosity, this program compiles under ocamlc, too.
Upvotes: 12
Views: 535
Reputation: 4274
That's a very useful feature to avoid bugs and ease the reading of big integers:
1_000_000_000
is easier to read than 100000000
(did you notice I forgot a zero ?).
Upvotes: 6
Reputation: 582
There is several programming language that accepts the underscore character as a non significant character in an integer. Ada, Perl, OCaml and probably some other language use it to separate thousand, millions and billions... but you can use _
anywhere inside the integer.
Upvotes: 4
Reputation: 30969
Underscores are allowed in numbers (and ignored) in OCaml. From http://www.cs.ru.nl/~tews/htmlman-3.10/lex.html#xhtoc5:
For convenience and readability, underscore characters (_) are accepted (and ignored) within integer literals.
Upvotes: 19