I would point out that in C, to have convenient support for things like decimal floating-point arithmetic, you need to add support for it at the language level, which is not the case at all in Julia, so the C standards committee has an entirely different set of constraints and motivations to work with.
Sure. But you have to agree that it’s pretty clear that one of these two reads better than the other:
# decimal literals with a string macro
x = dec"10.3" + dec"5.8" * dec"0.15"
# decimal literals with built-in support for parsing
# m is the suffix for decimal in e.g. C#, works similar to e.g. Julia's 0.15f0 for Float32
x = 10.3m + 5.8m * 0.15m
Adding support for a few more of these kinds of literals - or even an extension mechanism to enable registering your own type and suffix - is definitely useful, even if the equivalent program can already be written with today’s features.
// T
@declits begin
x = 0.70 * 0.05
println(x)
end
f0 = 2
@assert 0.5f0 == 0.5
@assert 0.5*f0 == 1
Somehow the parser knows that the first one isn't a case of juxtaposition - what I and Scott are suggesting is a way to, outside of Base, register literal syntaxes for other types.
I would prefer those to be suffixes, but prefixes would also be an improvement over the current situation. For example, even if the difference between 0m0.15 m"0.15" is only one character, syntax highlighting etc will work significantly better for the former.
// T
I am unfamiliar with the application domain (banking etc), but I wonder
whether they need to have a lot of literals in the code --- my first
guess would be that values mostly come from a database.
Just to add my two cents, I can see two possibilities.
First the underscore `_` character has a special place in numerical literals already. Perhaps a trailing underscore could precede a numerical literal macro, like 123456789987654321_bigint or 1.024_dec (or _m). Then juxtaposition rules are only changed slightly for references beginning with _ (sort of like `1.0 * f0` would require a space in the juxtaposition).
On Wednesday, April 6, 2016 at 1:22:41 PM UTC, Andy Ferris wrote:Just to add my two cents, I can see two possibilities.
@decimal function ....1.024..end