Raku is an incredibly rich, flexible, and powerful programming language. Its flexibility allows for programmers to write expressive code which fits their own style.
Raku is a large language with plenty of depth to learn, explore, and experiment with. This syllabus aims to cover the fundamentals for you to get started.
Object Oriented Programming is at the heart of Raku, however it does not impose object oriented programming practices. Because of its object oriented nature, this syllabus will often make references to objects, classes, and methods.
We'll only use scalar variables in basics to keep things simple.
Scalar variables are identifiers prefixed with the $
sigil.
Scalar variables can contain virtually anything, and have a default type of Any
.
Most variables you use will need a declaration.
For now, stick with my
and constant
.
my $foo;
constant $BAR;
A subroutine is declared with the sub
declarator.
A sub
declaration is followed by an optional identifier, followed by an optional signature, followed by a block.
Subrouties (among other things) can be exported by adding the is export
trait.
A subroutine can be called with a postcircumfix ( )
operator on the identifier.
sub foo ($bar) is export { ... } # Subroutine definition
foo($bar); # Subroutine call
Raku has a wide variety of operators.
We will be using some basic mathematical operators in Raku, such as +
and -
, for the exercises in the basics concept.
say 0.1 + 0.2 - 0.3;
# Raku is not like other languages -> https://0.30000000000000004.com/#raku
You can easily define your own operators in Raku if you wish. Most built-in operators are also available as subroutines.
There are several types of packages in Raku. We will only use module
in basics.
To declare an entire file as a module
, the module declaration is prefixed with unit
.
unit module Foo;
sub bar () { ... }
Raku has single-line and multi-line/embedded comments.
Single-line comments start with #
and continue until the end of the line.
Multi-line/embedded comments start with a hash followed by a backtick and a Unicode Open Punctuation character. They end with a paired matching close character.
# This is a single-line comment
#`(
This is a
multi-line/embedded comment
)
Variable and subroutine identifiers in Raku are styled in kebab-case
.
Constants are styled in ALL-CAPS
.
Package names are styled in PascalCase
.