Perl 6 Deep Dive
eBook - ePub

Perl 6 Deep Dive

Andrew Shitov

Condividi libro
  1. 402 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Perl 6 Deep Dive

Andrew Shitov

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Learn Perl 6 effortlessly to solve everyday problemsAbout This Book• Filled with practical examples, this comprehensive guide explores all aspects of Perl 6.• Leverage the power of Perl 6 concurrency to develop responsive and high-performant software.• Delves into various programming paradigms (such as Object Oriented, functional, and reactive) that can be adopted by Perl 6 developers to write effective code. Who This Book Is ForThis book is for developers who would like to learn the Perl programming language. A basic knowledge of programming is assumed. What You Will Learn• Learn the background from which Perl 6 appeared and how it developed.• How to use Rakudo to run your programs.• Various Perl 6 built-in types and details about their behavior• Understand how scalar variables, hash variables, and arrays work• Create meta operators and hyper operators• How classes work and how to build software based on the Object Oriented Paradigm• How Perl 6 provides support for concurrency, functional programming, and reactive programming.In DetailPerl is a family of high-level, general-purpose, interpreted, dynamic programming languages consisting of Perl 5 and Perl 6. Perl 6 helps developers write concise and declarative code that is easy to maintain.This book is an end-to-end guide that will help non-Perl developers get to grips with the language and use it to solve real-world problems.Beginning with a brief introduction to Perl 6, the first module in the book will teach you how to write and execute basic programs. The second module delves into language constructs, where you will learn about the built-in data types, variables, operators, modules, subroutines, and so on available in Perl 6. Here the book also delves deeply into data manipulation (for example, strings and text files) and you will learn how to create safe and correct Perl 6 modules. You will learn to create software in Perl by following the Object Oriented Paradigm. The final module explains in detail the incredible concurrency support provided by Perl 6. Here you will also learn about regexes, functional programming, and reactive programming in Perl 6.By the end of the book, with the help of a number of examples that you can follow and immediately run, modify, and use in practice, you will be fully conversant with the benefits of Perl 6.Style and approachThis book will take you through essential Perl 6 concepts so you can implement them immediately

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Perl 6 Deep Dive è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Perl 6 Deep Dive di Andrew Shitov in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming Languages. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2017
ISBN
9781787123458
Edizione
1

Working with Operators

Operators are the elements of the syntax of the language which perform actions over their operands and return a result. Perl 6 is a language with dozens of operators. Some of them are inherited from Perl 5 (directly or with modifications), some were invented especially for Perl 6. On top of the set of regular operators, Perl 6 defines the so-called meta-operators and hyper-operators, which extend the meaning of regular operators for working on a group of values.
In this chapter, we will cover the following topics:
  • Operator classification
  • Unary operators
  • Binary operators
  • Ternary operator
  • Bitwise operators
  • Miscellaneous operators
  • Operator precedence
  • Substitution meta-operators
  • Assignment meta-operators
  • Negation meta-operators
  • Reversed meta-operators
  • Creating hyper-operators
  • Types of hyper-operations
  • Reduction hyper-operators
  • Cross hyper-operators
  • Zip hyper-operator
  • Sequential hyper-operators

Operator classification

First, let's remind ourselves of some of the basic terminology that we need when talking about operators. Consider a simple example:
my $a = 10;
my $b = 20;
my $c = 0;
$c = $a + $b;
say $c; # 30
Let's concentrate on the following line of code:
$c = $a + $b;
Here, we tell the compiler to perform two actions—first, calculate the sum of the $a and $b variables, and second, assign the result to the third variable, that is, $c. There are two operators in this example—+ and =. Operators are presented by their one-character names. In this case, the names are chosen to copy the corresponding operators in mathematics. Later, we will see examples of other operators, which are not just a character. They can be, for example, a sequence of two or three non-alphabetical symbols, such as >= or <= operators. Or, they can be a string identifier, for example—cmp or eq.

Categories of operators

In the previous section, we saw an example of the + operator, which takes two arguments. There are many other operators that are similar to +. For example, * is the operator for multiplication. Like the + operator, the * operator takes two arguments and returns a value.
my $c = $a * $b;
This kind of operator is called an infix operator, or simply infix. The operands of such operators are often called the left-hand side and right-hand side operands. As the operators take two arguments, they are also often called binary operators.
Another kind of operator needs only one argument. These operators are called unary operators. A typical example of a unary operator is unary minus. In the following example, this operator negates the value of its argument:
my $a = 10;
my $b = -$a;
say $b; # prints -10
Notice that this operator uses the same character as the binary minus operator, but both the programmer and the compiler can distinguish between the two:
my $a = 10;
my $b = -$a; # unary minus, $b becomes -10
my $c = $a - $b; # binary subtraction, $c is 20
Different unary operators can be placed either before the argument or after it. For example, the ++ operator has two forms—prefix and postfix. The following example demonstrates the two alternatives:
my $a = 10;
++$a; # prefix operator ++
$a++; # postfix operator ++
The position of an operator (it is either placed before or after an argument) changes its meaning.
So far, we've met infix, prefix, and postfix operators. There are two more categories of operators in Perl 6.
Circumfix operators are another kind of unary operators. Unlike operators like unary -, circumfix operators consist of two complementary parts, such as parentheses. The only operand of a circumfix operator is placed between them, for example—the [$a] construction uses the [] circumfix operator that takes $a as an argument.
Finally, there are postcircumfix operators. They need two operands, and the syntax is the following—operand1[operand2]. One of the most practical examples of the postcircumfix operator is the function call. We've seen it a few times already—add($a, $b).
Let's summarize the operator categories in the following table using the + operator symbol as an example:
Category Syntax
infix operand1 + operand2
prefix +operand
postfix operand+
circumfix (operand)
postcircumfix operand1[operand2]

Operators as functions

Operators perform some actions over their arguments. Operator's arguments are called operands. In the preceding example, the + operator takes two operands, $a and $b. The = operator also takes two operands—on the left side of it, it expects the variable, to which it will assign the value of the operand on the right side.
In any programming language, operators are simply a handy syntactical solution to have more expressive programs and can be replaced with calling a function. For example, in the preceding example, you write $c = $a + $b, but you can also do the same by calling the add function that we saw in Chapter 1, What is Perl 6?. Let's rewrite the previous example:
my $a = 10;
my $b = 20;
my $c = 0;
$c = add($a, $b);
say $c; # 30

sub add($a, $b) {
return $a + $b;
}
Of course, the add function uses the + operator itself, but we cannot avoid it here because there are no more low-level functions for addition in Perl 6. The purpose of the example was to demonstrate that operators can always be treated as functions that accept a few arguments and return a value, but you do not call them directly; rather via a good-looking operator.
In Perl 6, you may use the functional style when working with operators. For that, use the key...

Indice dei contenuti