"Perl 6 Operators"


Speaker: Juerd
Duration: 45 minutes
Level: Advanced

Het Nederlandse origineel is hier.

Introduction

Summary

Perl 5 operators

-> ++ -- ** ! ~ \ and u+ u- =~ !~ * / % x + - . << >> < > <= >= lt gt le ge == != <=> eq ne cmp & | ^ && || .. ... ?: = op= , => not and or xor

Operators that stay the same

! != % && * ** + ++ - -- .. / < <= <=> == > >= \ and and cmp eq ge gt le lt ne not op= or xor ||

Changing operators

-> . ~ ^ ?: x => & | ^ << >>

New operators

<> «» »« | & ^ := ::= =:= ^^ // ? + ~ true err ¥ : ...

The big shift

More changes

Bitwise ops

& | ^ < >
+ +& +| +^ +< +> numeric
~ ~& ~| ~^ ~< ~> stringy
? ?& ?| ?^ boolean

Linenoise explained

(»~&=«)

$foo ~&= " "
is just
$foo = $foo ~& " "

»« explained later on

Smart matching

Examples with ~~

if $string ~~ $regex { ... }
if @array  ~~ $element { ... }    # grep
if $string ~~ $substring { ... }  # eq
if $class  ~~ SuperClass { ... }  # isa

Filler

Defined-or

my $foo = $input || 'default';
my $foo = $input // 'default';

err is the low precedence version

Word lists

Pairs

:foo means :foo(1)

Hash subscripts

Binding

Forcing context

Zipping

¥ or Y or zip()

@foo ¥ @bar
# is actually
@foo[0], @bar[0],
@foo[1], @bar[1],
@foo[2], @bar[2], ...

Hyper

@quux = map { $_ + 3 } @foo
@quux = @foo »+ 3;

@quux = map { @foo[$_] + @bar[$_] }
0 .. min(@foo.last, @bar.last);
@quux = @foo »+« @bar;

Line noise explained

@ips »~&=« @netmasks

Junctions!!!

if $foo == 'foo' | 'bar' { ... }
if $foo & $bar > 3 { ... }

Kinds of junctions

Ease

if  $a != $c
and $a != $d 
and $b != $c 
and $b != $d { ... }
becomes
if $a & $b == $c ^ $d { ... }

More ease

if  $a != $d and $a != $e and $a != $f
and $b != $d and $b != $e and $b != $f
and $c != $d and $c != $e and $c != $f { ... }
becomes
if all($a, $b, $c)
== none($d, $e, $f) { ... }

Real power

if all(@foo) != none(@bar)
    { ... }

Junctions as normal values

my $junc = 11 | 20;

$junc += 5;
# $junc is now 16 | 25

$j2 = sqrt($junc);
# $j2 is now 4 | 5

Not explained

Books

The end