Raku (programming language)
Adapted from Wikipedia · Adventurer experience
Raku is a programming language that is part of the Perl family. It used to be called Perl 6, but in October 2019, it was renamed to Raku. Raku uses ideas from many different old and new programming languages to make something new. It does not try to work exactly like Perl, but it has a special compatibility mode that can help with this. The design of Raku began in the year 2000.
History
Raku started as Perl 6. It was first talked about on July 19, 2000, by Larry Wall during a talk called State of the Onion 2000. The main idea was to make the language better by fixing old problems and making things easier to use. Everyone could help suggest changes.
Larry Wall looked at all the suggestions and wrote explanations called "Apocalypses". Later, these were turned into "Synopses" to keep up with changes. Today, Raku's rules are checked using tests called "roast", and the old Synopses are kept for history. There are also writings called "Exegeses" that show how to use the new rules with examples.
People talk about Raku using an online chat room, special email lists, and a place to share code called GitHub.
The big goal was to fix confusing parts of the old language. Because of these big changes, Raku would not work exactly like the old Perl, so it was finally renamed from Perl 6 to Raku.
Raku's mascot is a butterfly named Camelia, the Raku bug. Her name remembers Perl’s camel mascot and plays on the idea of a “bug” in software. Her design includes spiral patterns that look like “P6” and an off-center eye, which is a fun joke. The bright and lively design was meant to encourage kindness and openness in the Raku community.
Implementations
As of 2017, only the Rakudo implementation was still being worked on. Raku doesn’t have one official version; instead, anything that works with the official test suite counts as Raku.
Rakudo Perl 6 can work with several virtual machines, like MoarVM, the Java Virtual Machine, and JavaScript. MoarVM is a special virtual machine made just for Rakudo and the NQP Compiler Toolchain. There’s a layer called Not Quite Perl 6 (NQP) between Raku and these virtual machines. NQP helps Raku read its own rules and create code for different systems. Much of Rakudo is written in Raku itself or in NQP. Rakudo isn’t fully self-contained, and there aren’t current plans to make it a system that can build itself from scratch.
Historical implementations
Pugs was the first version of Perl 6, written in Haskell by Audrey Tang. Once the most advanced version, Pugs became quiet by mid-2007, with only updates to match the Glasgow Haskell Compiler. By November 2014, Pugs was no longer being updated.
In 2007, two small versions called v6-MiniPerl6 (“mp6”) and v6-KindaPerl6 (“kp6”) were made to help create the Perl-6.0.0 STD. The STD is a full set of rules for Perl 6, written in Perl 6. In theory, any system that can understand the STD and create running code could help start a full Perl 6 compiler. Kp6 is now built by mp6 and can work with different systems. Mp6 and kp6 aren’t full Perl 6 versions; they only have the basic features needed to start a full Perl 6 compiler.
Yapsi was a Perl 6 compiler and system written in Perl 6. Because of this, it needed an existing Perl 6 interpreter, like one of the Rakudo Star releases, to operate.
Niecza was another big effort to build Perl 6, focusing on making it fast and efficient. It aimed to work with the Common Language Infrastructure.
Module system
In Raku, modules are special parts of code that you can use in your programs. Each module must have a name, a version number, and the name of the person or group who made it. This helps you choose the version you want, even if there are different versions.
Right now, the system that usually handles modules for Perl, called CPAN, doesn’t work for Raku modules yet. So, Raku uses its own new way to manage these modules. This system also lets you give a module a shorter, easier-to-remember name.
Major changes from Perl
Perl and Raku are related, but Raku has many changes to make programming easier and clearer. The main goal is to make simple things simple and complex things possible.
A specification
Raku started as a set of rules, unlike Perl. This means Raku can be recreated if needed, and programmers don’t need to read the inner workings to understand it. Perl’s rules are more flexible and can change between versions.
A type system
Raku adds a way to tell what kind of data a variable holds, like numbers or words, but this is optional. Programmers can choose to use it or not.
Formal subroutine parameter lists
Raku makes functions clearer by requiring lists of inputs. These lists can be used in different ways, making code easier to read.
Sigil invariance
In Perl, symbols before variables change based on use. Raku keeps these symbols the same, making code less confusing.
Object-oriented programming
Raku makes creating objects and classes easier. It keeps some of Perl’s ways but adds clearer methods to work with objects.
Regular expressions
Raku improves Perl’s strong text-matching abilities with more features and clearer rules.
Syntactic simplification
Raku simplifies some Perl rules, like removing extra parentheses in common situations.
Chained comparisons
Raku lets you link comparisons together easily, making code more readable.
Macros
Raku supports powerful macros, which can change code during its creation, making development more flexible.
Identifiers
Raku allows more characters in variable names, including many Unicode symbols, making names more expressive.
Examples
Hello world
The hello world program is a common way to start learning a new language. In Raku, you can write a hello world program like this:
say 'Hello, world';
There are other ways to do it too.
Factorial
The factorial is a math idea that can be shown in many ways in Raku. Here are a few examples:
- Using a simple rule
- Using a special rule for when the number is zero
- Using different ways to choose what to do next
- Using a choice operator
- Using different paths for different numbers
- Using a special tool to make the math shorter
- Making a new operator for factorial
- Remembering past answers to save time
Quicksort
Quicksort is a way to put lists in order. In Raku, you can write a quick and clear version of this idea:
- An empty list is already sorted
- For a list with items, pick the first item as a middle point
- Separate the rest of the list into items smaller and larger than the middle point
- Sort each group and put them together
Tower of Hanoi
Tower of Hanoi is a classic puzzle that shows how recursion works. This Raku version uses special rules for different numbers of disks:
- If there are no disks, do nothing
- For any number of disks, move all but one to a different peg, move the last disk, then move the others again
Books
Raku is part of the Perl family. It has had two sets of books published.
The first set began when Raku was first announced in 2000. These books describe Raku as it looked then and are now mostly out of date.
The second set started after version 1.0 was released in 2015. This set includes several books, with more being written. These books cover topics such as programming with Raku, solving problems with Raku, and exploring Raku’s features through examples and projects.
Related articles
This article is a child-friendly adaptation of the Wikipedia article on Raku (programming language), available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.
Safekipedia