What is Raku++

Raku++ is a compiler for the Raku programming language.

It’s an independent implementation in C++ and its source code is located in the ash/rakupp repo on GitHub.

Interpreter and Compiler

Raku++ is both an interpreter and a compiler. You can pass your Raku program to the single rakupp binary:

% cat > hello.raku
say 'Hello, World!';

% rakupp hello.raku 
Hello, World!

In this mode, the program is parsed and executed in a single session — in the same manner as other script languages work with their interpreters.

The second way to operate is to compile the program and run the binary:

% rakupp --exe -o hello hello.raku 
Compiled (native) hello.raku -> hello

% ./hello 
Hello, World!

Now you get a binary file hello, which you can ship without the need to have rakupp on the computer, where hello will be executed.

Compactness

Raku is a huge language, and if you are not using its full scale in a program, you can cut the unused parts away from the binary file. For example, Unicode tables can go if you don’t need them now.

% rakupp --exe -o hello-slim --slim hello.raku

The --slim flag is available out of the box. Also, there are some default heuristics that are applied if you didn’t turned them off explicitly. With the above command, the size of our Hello program became half of the original one:

% ls -lah hello*
-rwxr-xr-x@ 1 ash  staff   7.8M Aug 12 13:53 hello
-rwxr-xr-x@ 1 ash  staff   4.7M Aug 12 13:53 hello-slim
-rw-r--r--  1 ash  staff    21B Aug 12 13:47 hello.raku

Speed

The main goal of the whole Raku++ project is to get the compiler that will be extremely fast. Before any release, it’s always controlled that the new version does not get slower. We have a number of benchmark cases, also specifically designed to contain massive or hard calculations.

Raku++ parses the code so quickly, that you (again) feel the beauty of computers and the speed of the command line. Hit the Enter key and get the result — immediately (as the human sees it).

% time rakupp examples/fibonacci.raku 
. . .
rakupp examples/fibonacci.raku  0.01s user 0.01s system 27% cpu 0.058 total

There are a few dozen example files in the repository, you can use them with rakupp straight away. When you are done with examples, continue with the second bunch of sample Raku programs located in the showcase directory. There, you can find the examples of servers, text converters, programming language interpreters (yes, you’ll find ready-to-use interpreters of Lisp, Forth, Python, Perl, and JavaScript/TypeScript — all written in Raku and run by Raku++).

Linter, Profiler, and more

If you need to understand the program better, use the built-in features such as printing the AST (abstract syntax tree) or a generated C++ code used to produce a binary, or lint, or profile the program. The linter tells you if, for example, a variable is not used in the code or if there are dead branches. The profile lets you see where the program spends time the most:

% rakupp --profile examples/fibonacci.raku 
 . . .
Profile — wall time; builtins are attributed to their caller
   excl(ms)   incl(ms)      calls  routine
      1.127      1.127        225  fib-pair (/Users/ash/raku++/examples/fibonacci.raku)
      0.156      1.282         41  fib (/Users/ash/raku++/examples/fibonacci.raku)

Raku++ offers its own syntax highlighter, which genuinely understands when role is a keyword and when it’s a name of the routine in the user’s program. You can generate both HTML and ANSI versions.

% rakupp --ansi hanoi.raku 
sub hanoi($n, $from, $to, $via) {
    return if $n == 0;
    # Move the top n-1 disks off onto the spare peg.
    hanoi($n - 1, $from, $via, $to);
    # Move the largest remaining disk to its destination.
    $moves++;
    say "  move {$moves.fmt('%2d')}: disk $n   $from -> $to";
    # Bring the n-1 disks back on top.
    hanoi($n - 1, $via, $to, $from);
}

Do you want to use REPL, you are welcome:

% rakupp
Raku++ 3.14.0 — \h for help, ^D to exit
> sub postfix:<!>($n) {[*] 1..$n}
&postfix:<!>
> say 55!
12696403353658275925965100847566516959580321051449436762275840000000000000
True

Availability

Raku++ is available on many platforms: macOS (both Apple Silicon and Intel), Windows (including MinGW), Linux, OpenBSD; there are also GNU Guix and Nix configurations options. It’s possible to install it using brew, or you can run it right in the browser without any installation.

The in-browser version is an extremely useful tool — would you like to learn Raku or want to prototype some program. The playground at raku.online/play lets you do that.

You can also use online features to embed the runnable blocks in your web texts: blogs, articles courses, whatever:

my $now = DateTime.now;

say "Today is {$now.yyyy-mm-dd}.";
say "And it’s {$now.hh-mm-ss} right now.";

Modules

Raku++ can use the modules installed by the zef utility. One of the showcases, modinfo, demonstrates how you can work with the installed modules, and prints information about them:

% rakupp showcase/modinfo/modinfo.raku --installed
distribution            version   auth                        deps  rdeps  provides
─────────────────────────────────────────────────────────────────────
Abbreviations           2.2.3     zef:tbrowder                   0      1         1
AlgorithmsIT            0.0.4     zef:tbrowder                   0      1         2
Color                   1.004001  zef:raku-community-modules     0      0         5
Config                  3.0.4     cpan:TYIL                      4      0         8
Data::Dump              0.0.18    zef:tony-o                     0      0         1
 
. . .

zef                     1.1.3     zef:ugexe                      0      0        32
39 distributions, 33 internal edges, 3 external references

The modinfo tool is created to deliberately use a number of the modules from the Raku ecosystem.

Conformance

Currently, the language supports the majority of the Raku elements. Raku comes with the official test suite called Roast, of which Raku++ successfully passes more than 90%. There’s also an official documentation with hundreds of code examples, where Raku++ correctly execute about 88% of the executable samples.

It’s a separate pleasure to scroll the divergences page that lists the atoms of Raku which are implemented or behave incorrectly yet.

It worth mentioning that Raku++ fully supports the Unicode version UCD 17.

Versions

Raku++ is keeping its pace in development, let me list a few big milestones:

  • 1.0.0 — 90% of Roast passing
  • 1.1.0 — 100% of the Unicode support
  • 1.5.1 — even faster: the hottest tests are 10-15% faster
  • 1.5.2 — external modules pass their own tests
  • 1.7.0 — another 10% off for the hottest test cases
  • 2.0.0 — 50 of the most popular Raku modules fully pass
  • 3.0.0 — no GIL, pure concurrency
  • 3.1.0 — Raku++ can be linked to/from external programs
  • 3.14.0 — slimmer binaries

Learn Raku, Use Raku, Love Raku

If you are ready to learn Raku, you can start with the online Raku Tour.

When you are done, pass the exam, also all in the browser.

Would you like to learn deeply, follow the Complete Course or Raku.

Interested about the Raku++ compiler internals? Here you are, a detailed ~300-page overview of how it works and why: Raku++ Internals.

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code