Programming languages are fascinating. Even if you think that these are the last days when you need to write code yourself, that only gives you more time to enjoy the beauty.
In this article I would like to showcase some of the small but astonishing features of Raku. Even if you never had a chance to install a compiler on your machine, you can run all the examples below in the online – the price of the trade-off between speed, compactness, and exactness.
In Raku, 0.1 + 0.2 equals 0.3 exactly:
say 0.1 + 0.2 == 0.3; # True
to point you to the playground with the code filled in. All you need is to press the Run button and see the magic.
Similarly, 0.1 + 0.2 - 0.3 is an exact zero. :
say ⅓.numerator; # 1
say ⅓.denominator; # 3
And yes, Unicode fractions are understood, together with any kind of digits :
say 2⁵; # 32
say 5² + 12² == 13²; # True
The second line is the 5–12–13 Pythagorean triple, checked in one readable line.
Integers have no ceiling
An integer in Raku is as long as it needs to be. There is no 64-bit cliff to fall off, no special "big integer" import – the numbers simply grow :
say 97.is-prime; # True
say (2¹²⁷ − 1).is-prime; # True
The second number is a Mersenne prime of 39 digits, tested as casually as the small one. Notice the minus sign in 2¹²⁷ − 1: it is not the ASCII hyphen but the true Unicode minus, and Raku is perfectly happy with either.
Operators from the maths textbook
Superscripts are not the only notation rescued from the maths textbook. The multiplication and division signs, and the comparison signs with the slash already crossed through, are all ordinary Raku operators :
say [≤] 1, 2, 5, 9; # True
say [≤] 3, 1, 2; # False
π, τ, and ∞
The constants you know from school are predefined :
say ∞ > 10¹⁰⁰; # True
say (1 .. ∞)[^5]; # (1 2 3 4 5)
The range is lazy, so nobody attempts to materialise the rest of it.
And when you do want floating point
Floats did not go anywhere – you ask for them with scientific notation playground, which is powered by , and everything shown here prints exactly the same on both.
The next article in this series opens the second cabinet of curiosities: Unicode – strings that count a seven-codepoint emoji as one character, a variable named $Δ, and a file called café-☕.txt.
SOCIAL SHARE CARD GENERATOR