We’ve added a small, but useful syntax to our BoxLang parser that comes from multiple other languages. There’s been a lot of talk recently about what sort of features from other languages actually make sense to include in BoxLang. Just because a feature solves a problem in langage X doesn’t mean it serves a purpose and is idiomatic to BoxLang. In this case, there is wide precedent and the usefulness seems to extend easily to BL.
Numeric placeholders allow you to place underscore characters (_
) inside of a numeric literal for readability. Take a number like this
n = 1000000000
That’s 1 billion. Or was it 1 million? Or maybe it was 100 million… pauses to re-count.
With numeric place holders, your code can look like this:
n = 1_000_000_000
Ahh, so it was 1 billion! There’s no rules on where you can place the underscores, so long as they are INSIDE the number and not leading or trailing. Heck, this is valid (though pointless):
n = 1_0_0_0_0_0_0_0_0_0
You can also place numeric separators in decimals
n = 3.141_592_653_59
and in the exponent of scientific notation
1e2_345
These underscores are simply thrown away at compile time. They are not represented in the bytecode and will not appear anywhere in your running app. They are purely for readability in your source code.
More info on the ticket.