Perl 6 Data Structures
Herbert Breunung
CPAN: lichtkind
Kephra 0.4.3.32
Kephra Logo
As Hieroglyph
Mansfelder Land
Mansfelder Land
Egypt aka Khem
Got A Camel
Became Velociraptor
Camelia
Camel ia
 
Cockaigne
Holy Grail
Beauty And Order
Data Structures
 
@rrays And %ashes
$calars Too
Every Day Perl 5 <ul>@cities   = ( 'roma' ,   'milano' ,   'turino' ); </ul>
Perl 5 & 6 <ul>@cities   = ( 'roma' ,   'milano' ,   'turino' ); </ul>
Perl 5 <ul>@cities   = qw( roma   milano   turino ); </ul>
Perl 6 <ul>@cities   = qw( roma   milano   turino ); @cities   = < roma   milano   turino >; </ul>
With Interpolation Like “ “ <ul>@cities   = qw( roma   milano   turino ); @cities   = < roma   milano   turino >; @cities ...
Perl 5 & 6 <ul>@cities   = ( 'roma' ,   'milano' ,   'turino' ); </ul>
Still P5 & P6 <ul>@cities   = ( 'roma' ,   'milano' ,   'turino' ); @cities   =  'roma' ,   'milano' ,   'turino' ; </ul>
Braces Now Just Group <ul>@cities   = ( 'roma' ,   'milano' ,   'turino' ); @cities   =  'roma' ,   'milano' ,   'turino' ...
Item Context <ul>$cities   = ( 'roma' ,   'milano' ,   'turino' ); $cities   =  'roma' ,   'milano' ,   'turino' ; </ul>
Item Context <ul># Parcel() $cities   = ( 'roma' ,   'milano' ,   'turino' ); # Str() $cities   =  'roma' ,   'milano' ,  ...
What Is Str ? <ul># Parcel() $cities   = ( 'roma' ,   'milano' ,   'turino' ); # Str() - 'roma' is a string $cities   =  '...
Just the first value? <ul># Parcel() $cities   = ( 'roma' ,   'milano' ,   'turino' ); # $a, $b, $c = 1, 2, 3; $cities   =...
What is a Parcel ? <ul># Parcel – type of a signiture $cities   = ( 'roma' ,   'milano' ,   'turino' ); # Str() $cities   ...
() reminds you on what? <ul># Parcel – like in function(1,2,3); $cities   = ( 'roma' ,   'milano' ,   'turino' ); # Str() ...
Parcel <ul># have positional and named args $cities   = ( 'roma' ,   'milano' ,   'turino' ); # Str() $cities   =  'roma' ...
Container Types <ul># Array() $cities   = [ 'roma' ,   'milano' ,   'turino' ]; # Parcel() $cities   = ( 'roma' ,   'milan...
Array() ne List() ne Parcel() <ul># List() $cities  =  @( 'roma' ,   'milano' ,   'turino' ); # Parcel() $cities   = ( 'ro...
Just A List <ul># List() $cities  = list ( 'roma' ,   'milano' ,   'turino' ); # List() $cities   = ||( 'roma' ,  'milano'...
Array Object <ul>$cities   = [ 'roma' ,   'milano' ,   'turino' ]; @cities   =  'roma' ,   'milano' ,   'turino' ; say   $...
Number Of Elements <ul>say   length   @cities ;  # 3 say elems  @cities ;  #  3 # no length </ul>
elems Is A Method Too <ul>say   length   @cities ;  # 3 say  @cities . elems ;  # 3 </ul>
On A Scalar Too <ul>say   scalar  @$cities ;  # 3 say  $cities . elems ;  #  3 </ul>
Content From Scalar <ul>say   “@$cities“ ;  # roma ... say  $cities ;  #  roma ... </ul>
Scalar Context <ul>say   “@cities“ ;  # roma ... say  $( @cities ) ;  #  roma ... </ul>
Scalar Context <ul>say   “@cities“ ;  # roma ... say  item( @cities ) ;  #  roma ... </ul>
Numeric Context <ul>say   scalar   @cities ;  # 3 say  +   @cities ;  #  3 </ul>
Numeric Context <ul>say   scalar   @$cities ;  # 3 say  +   $cities ;  #  3 </ul>
Boolean Context <ul>say   values   @cities ;  # romami... say  ?   @cities ;  #  Bool::True </ul>
String Context <ul>say   “@cities“ ;  # roma milano say  ~   @cities ;  #  roma milano ... </ul>
. Became ~ <ul>say   “@cities“ ;  # roma milano say  “...“   ~   @cities ;  # ...roma mila..   </ul>
“ “  Works in P6 Too <ul>say   “ @cities“ ; # roma milano turino say  “@cities“ ; #  roma milano turino? </ul>
Not Quite <ul>say   “@cities“ ;  # roma milano ... say  “@cities“ ;  #  @cities </ul>
Add [] <ul>say   “@cities“ ;  # roma milano say  “@cities[]“ ; #  roma milano ... </ul>
Was No Special Case <ul>say   “@cities“ ;  # roma milano say  @cities [] ;   #  roma milano ... </ul>
Perl 5 & 6 <ul>say  @cities ;  # romamilanoturino say  @cities ;  # roma milano turino </ul>
When Data Gets Deeper
STD Perl 5 <ul>use   Data::Dumper ; say   Dumper ( @cities ); </ul>
$VAR1 = 2;  $VAR2 = 3; $VAR3 = 4; $VAR4 = 5; $VAR5 = 6; $VAR6 = 7; $VAR7 = 7; $VAR8 = 2; $VAR9 = 5; $VAR10 = [ 'a', 'b', '...
$VAR1 = 2;  $VAR2 = 3; $VAR3 = 4; $VAR4 = 5; $VAR5 = 6; $VAR6 = 7; $VAR7 = 7; $VAR8 = 2; $VAR9 = 5; $VAR10 = [ 'a', 'b', '...
He Fixed That <ul>use   YAML ;  #  Data::Dumper  sucks say   Dump  @cities ;  </ul>
--- - 2 - 3 - 4 - 5 - 6 - 7 - 7 - 2 - 5 - - a - b - c [2, 3, 4, 5, 6, 7, 7, 2, 5, [&quot;a&quot;, &quot;b&quot;, &quot;c&q...
--- - 2 - 3 - 4 - 5 - 6 - 7 - 7 - 2 - 5 - - a - b - c [2, 3, 4, 5, 6, 7, 7, 2, 5, [&quot;a&quot;, &quot;b&quot;, &quot;c&q...
Perl 6 <ul>say  @cities . perl ; </ul>
Perl 6 <ul># works to any depth say  @cities . perl ; $ [&quot;roma&quot;, &quot;milano&quot;, &quot;turino&quot;] </ul>
Perl 5 <ul>say  $cities [ 2 ];  # turino </ul>
Perl 6 <ul>say  $cities [ 2 ];  # turino say  @cities [ 2 ];  # turino </ul>
Array In A Scalar <ul>say  $cities [ 2 ];  # Perl 6 too say  @cities [ 2 ];  # turino </ul>
Same Container Type <ul>$cities   = [ 'roma' ,   'milano' ,   'turino' ]; say  $cities [ 2 ];  # $cities.WHAT say  @cities...
Array Objects <ul>say  $cities [ 2 ];  # Array() say  @cities [ 2 ];  # Array() </ul>
Say Is Just A Method <ul>say  $cities [ 2 ];  # turino @cities [ 2 ]. say ;  # too </ul>
[ ] Too (Like Any Op) <ul>say  $cities .[ 2 ];  #  2 is a parameter @cities .[ 2 ]. say ;  # too </ul>
2 == Last Index <ul>say  $cities [ 2 ];  # turino say  @cities [ 2 ];  # too </ul>
Perl 5 <ul>say  $cities [ -1 ];  # turino say  @cities [ 2 ];  # too </ul>
Perl 6 <ul>say  $cities [ -1 ];  # turino say  @cities [* -1 ];  # too </ul>
Whatever * <ul>say  $cities [ -1 ];  # turino say  @cities [*- 1 ];  # too #parameter – closure with 1 argument </ul>
Whatever * <ul>say  $cities [ -1 ];  # turino say  @cities [* /  2 ]; # milano </ul>
Whatever * <ul>say  $cities [ -1 ];  # turino say  @cities [*];  #   roma milano turino </ul>
Whatever * <ul>say  $cities [ -1 ];  # turino say  @cities [];  #   roma milano turino # defaults to * </ul>
LoL <ul>say  @cities [ 1 ][ 1 ]; </ul>
List Of List <ul>@cities  = [< roma .. >], [< berlin .. >]; say  @cities [ 1 ][ 1 ]; say  $cities [ 1 ; 1 ]; </ul>
Let's Play A Game
Count the Smurfs
Count
Count <ul>How many elements does this list have? </ul>
Round 1
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ; </ul>
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ;  # 4 my  @number  = ( 1 ,  2 ,  3 ,  4 ); </ul>
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ;  # 4 my  @number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  @number  =  ...
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ;  # 4 my  @number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  @number  =  ...
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ;  # 4 my  @number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  @number  =  ...
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ;  # 4 my  @number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  @number  =  ...
How Many Elements ? <ul>my  @number  =  1 ,  2 ,  3 ,  4 ;  # 4 my  @number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  @number  =  ...
Round 2
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  </ul>
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  # 1 my  $number  = ( 1 ,  2 ,  3 ,  4 );  </ul>
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  # 1 my  $number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  $number  =  ...
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  # 1 my  $number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  $number  =  ...
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  # 1 my  $number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  $number  =  ...
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  # 1 my  $number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  $number  =  ...
How Many Elements ? <ul>my  $number  =  1 ,  2 ,  3 ,  4 ;  # 1 my  $number  = ( 1 ,  2 ,  3 ,  4 );  # 4 my  $number  =  ...
Round 3
How Many Elements ? <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); </ul>
How Many Elements ? <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); @number  =  1 ,   @pd ,  4 ; </ul>
How Many Elements ? <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); @number  =  1 ,  @pd ,  4 ;  # 6 @number  =  1 ,  $...
How Many Elements ? <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); @number  =  1 ,  @pd ,  4 ;  # 6 @number  =  1 ,  $...
item & list = Conext Ops <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); @number  =  1 ,  @pd ,  4 ;  # 6 @number  =  1...
Nil = Nothing <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); @number  =  1 ,  @pd ,  4 ;  # 6 @number  =  1 ,  $pd ,  ...
Nil = Nothing <ul>my  $pd   =   my  @pd  = ( 3 ,  1 ,  4 ,  1 ); @number  =  1 ,  @pd ,  4 ;  # 6 @number  =  1 ,  $pd ,  ...
And The Winner Is ...
Perl 5 <ul>@digits   = (  4  ) x  5 ;  # (4,4,4,4,4) </ul>
Perl 6 <ul>@digits   = (  4  ) x  5 ;  # (4,4,4,4,4) @digits   =  4  xx  5 ;  # 4,4,4,4,4 </ul>
Multiply Strings <ul>@digits   =  4  x  5 ;  # '44444' @digits   =  4  x  5 ;  # '44444' </ul>
Multiply Strings <ul>@digits   =  4  x  5 ;  # '44444' @digits   = ( 4 ) x  5 ;  # '44444' </ul>
Multiply Strings <ul>@digits   =  '1 2'   x  3 ;  # '1 21 21 2' @digits   = ( 1 , 2 ) x  3 ;  # '1 21 21 2' </ul>
Multiply Lists <ul>@digits   = ( 1 , 2 ) x  3 ;  #  1,2,1,2,1,2 @digits   = ( 1 , 2 ) xx  3 ;  #  1,2,1,2,1,2 </ul>
Perl 5 <ul>@digits   = (  0  ..  9  );  # range op </ul>
Perl 5 & 6 <ul>@digits   = (  0  ..  9  ); </ul>
Perl 6 <ul>@digits   =  0  ..  9 ; </ul>
Perl 6 <ul>@digits   = ^  10 ;  # 0 .. 9 </ul>
0 Is Given <ul>@digits   =  0  ..^  10 ;  # 0 .. 9 </ul>
^ Excludes The Range <ul>@digits   =  -1  ^..^  10 ;  # 0 .. 9 </ul>
Sequence Operator <ul>@digits   =  0  ...  9 ;  </ul>
Linear <ul>@digits   =  0  ...  9 ;  # 0 .. 9 </ul>
Arithmetic <ul>@digits   =  0  ...  9 ;  # 0 .. 9 @odd   =  1 , 3  …  9 ;  # 1,3,5,7,9 </ul>
Geometric <ul>@digits   =  0  ...  9 ;  # 0 .. 9 @odd   =  1 , 3  …  9 ;  # 1,3,5,7,9 @bin   =  1 , 2 , 4  …  1024 ; #..,8...
Fibonacci <ul>@digits   =  0  ...  9 ;  # 0 .. 9 @odd   =  1 , 3  …  9 ;  # 1,3,5,7,9 @bin   =  1 , 2 , 4  …  1024 ; #..,8...
Watch Your Limit <ul>@odd   =  1 , 3  …  10 ;  # 1,3,.. * </ul>
Infinite List <ul>@odd   =  1 , 3  …  10 ;  # 1,3,.. * @number   =  0  .. *;  # 0 .. Inf </ul>
Certain Elements <ul>@odd   =  1 , 3  …  10 ;  # 1,3,.. * @number   =  0  .. *;  # 0 .. Inf say   @odd [ 1 ];  # 3 say   @...
All Elements <ul>@odd   =  1 , 3  …  10 ;  # 1,3,.. * @number   =  0  .. *;  # 0 .. Inf say   @odd [*];  # waiting ... say...
Number Of Elements <ul>@odd   =  1 , 3  …  10 ;  # 1,3,.. * @number   =  0  .. *;  # 0 .. Inf say   +  @odd ;  # waiting ....
What Happened? <ul>$number   =  0  .. *;  # 0 .. Inf say   $number . WHAT ;   # Range() </ul>
Guess Output? <ul>$number   =  0  .. *;  # 0 .. Inf say   $number ;  # ? </ul>
First Element <ul>$number   =  0  .. *;  # 0 .. Inf say   $number ;  # 0 </ul>
Infinite List <ul>$number   =  0  .. *;  # 0 .. Inf say   @( $number );  # digits ... </ul>
Array <ul>@number   =  0  .. *;  # 0 .. Inf say   @number [ 5 ]; </ul>
Generates As Needed <ul>@number   =  0  .. *;  # 0 .. Inf say   @number [ 5 ];  #   @number.reify(5) </ul>
Internal Representation <ul>@number   =  0  .. *;  # 0 .. Inf say   @number . reify ( 5 ). perl ; # (0, 1, 2, 3, 4, 5, 6.....
You Know These <ul>shift  unshift push  pop  splice  reverse map  grep  </ul>
Perl 5 <ul>%opera   = ( 'verdi'  =>  'Aida' , 'puccini'  =>  'Turandot' , 'rossini' =>  'Il barbiere' , ); </ul>
Perl 6 <ul>%opera   = ( 'verdi'  =>  'Aida' , 'puccini'  =>  'Turandot' , 'rossini' =>  'Il barbiere' , ); </ul>
No Grouping Needed <ul>%opera   = 'verdi'  =>  'Aida' , 'puccini'  =>  'Turandot' , 'rossini' =>  'Il barbiere' , ; </ul>
Still Hash Object <ul>%opera   =  'verdi'  =>  'Aida' , 'puccini'  =>  'Turandot' , 'rossini' =>  'Il barbiere' , ; %opera...
New Pair Syntax <ul>%opera   = : verdi ( 'Aida' ), : puccini ( 'Turandot' ), : rossini ( 'Il barbiere' ), ; %opera . WHAT ...
With Autoquoting <ul>%opera   =  : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ; %opera . WHAT   eq...
Item Context <ul>$opera   =  : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ; $opera . WHAT   eq   '...
With Grouping <ul>$opera   =  ( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); %opera . WHAT   eq...
Parcel Know Positions <ul>$opera   =  ( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); 0 verdi Ai...
Hash Context Op <ul>$opera   =  %( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); %opera . WHAT  ...
Hash Context Op <ul>$opera   =  hash( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); %opera . WHA...
Hash Generator Op <ul>$opera   =  { : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, }; %opera . WHAT ...
Hash Generator Op <ul>%opera   =  { : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, }; %opera . WHAT ...
Invariant Sigils <ul>%opera { 'rossini' };  # Il barbiere </ul>
Invariant Sigils <ul>%opera .{ 'rossini' };  # alias .at_key() </ul>
Remember qw() ? <ul>%opera { 'rossini' };  # Il barbiere %opera < rossini >;  </ul>
With Interpolation <ul>%opera { 'rossini' };  # Il barbiere %opera < rossini >;  %opera << $autore >>;  </ul>
Get 2 Operas <ul>%opera { 'rossini' ,  'puccini' }; %opera < rossini puccini >;  %opera << @autore >>;  </ul>
Also Just Hashes <ul>$opera { 'rossini' ,  'puccini' }; $opera < rossini puccini >;  $opera << @autore >>;  </ul>
Works On Parcel() Too <ul>$opera { 'rossini' ,  'puccini' }; $opera < rossini puccini >;  $opera << @autore >>;  </ul>
Hash Methods <ul>%opera . keys ;  # verdi puccini ro... %opera . values ;  # aida turandot ... %opera . kv ;  # verdi aida...
On Arrays Too <ul>@cities . keys ;  # 0 1 2 @cities . values ;  # roma milano ... @cities . kv ;  # 0 roma 1 milano 2 ... ...
On Pairs <ul>$opera . key ;  # rossini $opera . value ;  # Il barbiere $opera . kv ;  #  </ul>
Other Hash Methods <ul>%opera . pairs ;  # list of pair obj. %opera . exists ;  # Bool %opera . delete ;  # 1 | 0 </ul>
Other Methods <ul>%opera . pairs ;  # list of pair obj. %opera . exists ;  # one at a time %opera . delete ;  # one at a t...
Hash In Context <ul>?  %opera ;  # bool context +  %opera ;  # num context ~  %opera ;  # string context </ul>
Hash In Context <ul>?  %opera ;  # Bool::True +  %opera ;  # 3 ~  %opera ;  # rossini Il barbiere </ul>
Value In Context <ul>?  %opera ;  # Bool::True +  %opera ;  # 3 ~  %opera ;  # rossini Il barbiere </ul>
New Hash Method <ul>say  %opera . invert ; Aida  verdi Turandot  puccini Il barbiere  rossini </ul>
Hash Generator <ul>my  %h  =  @cities . classify  ( {  uc substr (  $_ ,   0 ,   1  ) } ); say   %h ; $ R  roma M  milano ...
Hash Generator <ul>@cities . categorize ({  catsub ( $_   ) }); say   %h . perl ; </ul>
Hash Generator <ul>@cities . categorize ({  water ( $_   ) }); say   %h . perl ; {&quot;mare&quot; => [&quot;roma&quot;], ...
==> <ul>Pipes </ul>
Schwartz. Transform <ul>@results   =  map  {…},  sort  {…},  map  {...},  @input ; </ul>
Schwartz. Transform <ul>@results   =  map  {…},  sort  {…},  map  {...},  @input ; @results   =  map  {…} <==  sort  {…} <...
Schwartz. Transform <ul>@results   =  map  {…},  sort  {…},  map  {...},  @input ; @results   <==  map  {…} <==  sort  {…}...
Schwartz. Transform <ul>@results   =  map  {…},  sort  {…},  map  {...},  @input ; @input   ==>  map  {…} ==>  sort  {…} =...
Metaops
Metaops <ul>= ! R </ul>
Metaops <ul>>> [ ] [ ] X Z S </ul>
Metaops <ul>>> [ ] [ ] X Z S </ul>
Hyperoperator <ul>>> </ul>
Hyperoperator <ul>>> .hyper() </ul>
Simple Example <ul>( 1 .. 5 ) >>++ </ul>
That Works <ul>@number >>++ </ul>
Result <ul>@number >>++ 2 ,  3 ,  4 ,  5 ,  6 </ul>
More Complicated <ul>( 1 .. 5 ) >>+>>   1 </ul>
Check Your Spaces <ul>(1..5) _ >>+>> _ 1 </ul>
Same Result <ul>( 1 .. 5 ) >>+>>   1 2 ,  3 ,  4 ,  5 ,  6 </ul>
Reverse Hyper <ul>( 1 .. 5 ) <<+<<   1 </ul>
Right Side Rules <ul>( 1 .. 5 ) <<+<<   1 2 </ul>
Both Rule ? <ul>( 1 .. 5 ) >>+<<   1 </ul>
Yes Both! <ul>( 1 .. 5 ) >>+<<   1 Runtime Error !!! </ul>
Preserves LoL ? <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+>>   1 </ul>
Preserves LoL ! <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+>>   1 2 ,  3 ,  4 ,  5 ,  6 ,   [ 7 ,  8 ,  9 , 10 ] </ul>
On 2 Sides ? <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<<   ( 0 .. 4 , [ 1 .. 4 ]) </ul>
On 2 Sides ! <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<<   ( 0 .. 4 , [ 1 .. 4 ]) ( 1 ,  3 ,  5 ,  7 ,  9 , [ 7 ,  9 ,  11 ,  13 ]) <...
How About This? <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<<   ( 0 .. 4 , [ 1 .. 5 ]) </ul>
Checks Lengths <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<<   ( 0 .. 4 , [ 1 .. 5 ]) Runtime Error </ul>
Reduce <ul>[ ] .reduce </ul>
Do The Gauss <ul>[+] ( 1 .. 100 ) </ul>
Do The Gauss <ul>[+] ( 1 .. 100 ) 1  +  2  +  3  +  4  +  5  +  6  +  7  +  8  + ... </ul>
100+1 * 50 <ul>[+] ( 1 .. 100 ) 5050 </ul>
Chained Comparsion <ul>[<] ( 1 .. 100 ) </ul>
Chained Comparsion <ul>[<] ( 1 .. 100 ) 1  <  2  <  3  <  4  <  5  <  6  <  7  <  8  < ... </ul>
Chained Comparsion <ul>[<] ( 1 .. 100 ) Bool::True </ul>
Junction <ul>all ( 1 .. 100 ) >  0 </ul>
Junction <ul>all ( 1 .. 100 ) 1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  | ... </ul>
Junction <ul>all ( 1 .. 100 ) >  0 ( True ,   True ,  True , True , ... </ul>
Bool Context <ul>? all ( 1 .. 100 ) >  0 True </ul>
Bool Context <ul>? all ( 1 .. 100 ) >  1 False </ul>
Metaops <ul>>> [ ] [ ] X Z S </ul>
Triangle <ul>[ ] triangle() </ul>
Back To Gauss <ul>[+] ( 1 .. 100 ) </ul>
Returns A List <ul>[+] ( 1 .. 100 ) ((((( 1 )   +  2  )   +  3 )   +  4 )   +  5 )   +  6 ) + ... </ul>
Returns A List <ul>[+] ( 1 .. 100 ) ( 1 ,  3 ,  6 ,  10 ,  15 ,  21 ,  28 , ... </ul>
Metaops <ul>>> [ ] [ ] X Z S </ul>
Cross <ul>.crosswith X </ul>
Cross <ul>( 1 ,  2 ) X ( 1 ,  2 ) 11 ,  12 ,  21 ,  22 </ul>
Cross With Power <ul>( 1 ,  2 ) X** ( 1 ,  2 ) </ul>
Cross With Power <ul>( 1 ,  2 ) X** ( 1 ,  2 ) 1 ,  1 ,  2 ,  4 </ul>
Metaops <ul>>> [ ] [ ] X Z S </ul>
Zip <ul>.zipwith() Z </ul>
Zip <ul>( 1 .. 10 ) Z < a .. j > < 1a 2b 3c 4d 5e 6f   ...> </ul>
Zip <ul>for   @a  Z  @b ->   $a ,  $b  { </ul>
Zip <ul>( 1 .. 4 ) Z+ ( 1 .. 4 ) </ul>
Zip <ul>( 1 .. 4 ) Z+ ( 1 .. 4 ) 2 ,  4 ,  6 ,  8 </ul>
Metaops <ul>>> [ ] [ ] X Z S </ul>
Sequence <ul>.sequence S </ul>
__END__ ?
=begin END
Thank You
Upcoming SlideShare
Loading in …5
×

Perl 6 Datastructures

664 views
575 views

Published on

Perl 6 arrays and hashes explained in details, examples and with a guessing game

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
664
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • multiply a list
  • multiply a list
  • Perl 6 Datastructures

    1. 1. Perl 6 Data Structures
    2. 2. Herbert Breunung
    3. 3. CPAN: lichtkind
    4. 4. Kephra 0.4.3.32
    5. 5. Kephra Logo
    6. 6. As Hieroglyph
    7. 7. Mansfelder Land
    8. 8. Mansfelder Land
    9. 9. Egypt aka Khem
    10. 10. Got A Camel
    11. 11. Became Velociraptor
    12. 12. Camelia
    13. 13. Camel ia
    14. 15. Cockaigne
    15. 16. Holy Grail
    16. 17. Beauty And Order
    17. 18. Data Structures
    18. 20. @rrays And %ashes
    19. 21. $calars Too
    20. 22. Every Day Perl 5 <ul>@cities = ( 'roma' , 'milano' , 'turino' ); </ul>
    21. 23. Perl 5 & 6 <ul>@cities = ( 'roma' , 'milano' , 'turino' ); </ul>
    22. 24. Perl 5 <ul>@cities = qw( roma milano turino ); </ul>
    23. 25. Perl 6 <ul>@cities = qw( roma milano turino ); @cities = < roma milano turino >; </ul>
    24. 26. With Interpolation Like “ “ <ul>@cities = qw( roma milano turino ); @cities = < roma milano turino >; @cities = << roma milano $city >>; </ul>
    25. 27. Perl 5 & 6 <ul>@cities = ( 'roma' , 'milano' , 'turino' ); </ul>
    26. 28. Still P5 & P6 <ul>@cities = ( 'roma' , 'milano' , 'turino' ); @cities = 'roma' , 'milano' , 'turino' ; </ul>
    27. 29. Braces Now Just Group <ul>@cities = ( 'roma' , 'milano' , 'turino' ); @cities = 'roma' , 'milano' , 'turino' ; </ul>
    28. 30. Item Context <ul>$cities = ( 'roma' , 'milano' , 'turino' ); $cities = 'roma' , 'milano' , 'turino' ; </ul>
    29. 31. Item Context <ul># Parcel() $cities = ( 'roma' , 'milano' , 'turino' ); # Str() $cities = 'roma' , 'milano' , 'turino' ; </ul>
    30. 32. What Is Str ? <ul># Parcel() $cities = ( 'roma' , 'milano' , 'turino' ); # Str() - 'roma' is a string $cities = 'roma' , 'milano' , 'turino' ; </ul>
    31. 33. Just the first value? <ul># Parcel() $cities = ( 'roma' , 'milano' , 'turino' ); # $a, $b, $c = 1, 2, 3; $cities = 'roma' , 'milano' , 'turino' ; </ul>
    32. 34. What is a Parcel ? <ul># Parcel – type of a signiture $cities = ( 'roma' , 'milano' , 'turino' ); # Str() $cities = 'roma' , 'milano' , 'turino' ; </ul>
    33. 35. () reminds you on what? <ul># Parcel – like in function(1,2,3); $cities = ( 'roma' , 'milano' , 'turino' ); # Str() $cities = 'roma' , 'milano' , 'turino' ; </ul>
    34. 36. Parcel <ul># have positional and named args $cities = ( 'roma' , 'milano' , 'turino' ); # Str() $cities = 'roma' , 'milano' , 'turino' ; </ul>
    35. 37. Container Types <ul># Array() $cities = [ 'roma' , 'milano' , 'turino' ]; # Parcel() $cities = ( 'roma' , 'milano' , 'turino' ); </ul>
    36. 38. Array() ne List() ne Parcel() <ul># List() $cities = @( 'roma' , 'milano' , 'turino' ); # Parcel() $cities = ( 'roma' , 'milano' , 'turino' ); </ul>
    37. 39. Just A List <ul># List() $cities = list ( 'roma' , 'milano' , 'turino' ); # List() $cities = ||( 'roma' , 'milano' , 'turino' ); </ul>
    38. 40. Array Object <ul>$cities = [ 'roma' , 'milano' , 'turino' ]; @cities = 'roma' , 'milano' , 'turino' ; say $cities . WHAT # Array() say @cities . WHAT # Array() </ul>
    39. 41. Number Of Elements <ul>say length @cities ; # 3 say elems @cities ; # 3 # no length </ul>
    40. 42. elems Is A Method Too <ul>say length @cities ; # 3 say @cities . elems ; # 3 </ul>
    41. 43. On A Scalar Too <ul>say scalar @$cities ; # 3 say $cities . elems ; # 3 </ul>
    42. 44. Content From Scalar <ul>say “@$cities“ ; # roma ... say $cities ; # roma ... </ul>
    43. 45. Scalar Context <ul>say “@cities“ ; # roma ... say $( @cities ) ; # roma ... </ul>
    44. 46. Scalar Context <ul>say “@cities“ ; # roma ... say item( @cities ) ; # roma ... </ul>
    45. 47. Numeric Context <ul>say scalar @cities ; # 3 say + @cities ; # 3 </ul>
    46. 48. Numeric Context <ul>say scalar @$cities ; # 3 say + $cities ; # 3 </ul>
    47. 49. Boolean Context <ul>say values @cities ; # romami... say ? @cities ; # Bool::True </ul>
    48. 50. String Context <ul>say “@cities“ ; # roma milano say ~ @cities ; # roma milano ... </ul>
    49. 51. . Became ~ <ul>say “@cities“ ; # roma milano say “...“ ~ @cities ; # ...roma mila.. </ul>
    50. 52. “ “ Works in P6 Too <ul>say “ @cities“ ; # roma milano turino say “@cities“ ; # roma milano turino? </ul>
    51. 53. Not Quite <ul>say “@cities“ ; # roma milano ... say “@cities“ ; # @cities </ul>
    52. 54. Add [] <ul>say “@cities“ ; # roma milano say “@cities[]“ ; # roma milano ... </ul>
    53. 55. Was No Special Case <ul>say “@cities“ ; # roma milano say @cities [] ; # roma milano ... </ul>
    54. 56. Perl 5 & 6 <ul>say @cities ; # romamilanoturino say @cities ; # roma milano turino </ul>
    55. 57. When Data Gets Deeper
    56. 58. STD Perl 5 <ul>use Data::Dumper ; say Dumper ( @cities ); </ul>
    57. 59. $VAR1 = 2; $VAR2 = 3; $VAR3 = 4; $VAR4 = 5; $VAR5 = 6; $VAR6 = 7; $VAR7 = 7; $VAR8 = 2; $VAR9 = 5; $VAR10 = [ 'a', 'b', 'c' ]; [2, 3, 4, 5, 6, 7, 7, 2, 5, [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]] Data::Dumper O utput
    58. 60. $VAR1 = 2; $VAR2 = 3; $VAR3 = 4; $VAR4 = 5; $VAR5 = 6; $VAR6 = 7; $VAR7 = 7; $VAR8 = 2; $VAR9 = 5; $VAR10 = [ 'a', 'b', 'c' ]; [2, 3, 4, 5, 6, 7, 7, 2, 5, [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]] Too Wordy
    59. 61. He Fixed That <ul>use YAML ; # Data::Dumper sucks say Dump @cities ; </ul>
    60. 62. --- - 2 - 3 - 4 - 5 - 6 - 7 - 7 - 2 - 5 - - a - b - c [2, 3, 4, 5, 6, 7, 7, 2, 5, [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]] YAML O utput
    61. 63. --- - 2 - 3 - 4 - 5 - 6 - 7 - 7 - 2 - 5 - - a - b - c [2, 3, 4, 5, 6, 7, 7, 2, 5, [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]] He Did It Shorter
    62. 64. Perl 6 <ul>say @cities . perl ; </ul>
    63. 65. Perl 6 <ul># works to any depth say @cities . perl ; $ [&quot;roma&quot;, &quot;milano&quot;, &quot;turino&quot;] </ul>
    64. 66. Perl 5 <ul>say $cities [ 2 ]; # turino </ul>
    65. 67. Perl 6 <ul>say $cities [ 2 ]; # turino say @cities [ 2 ]; # turino </ul>
    66. 68. Array In A Scalar <ul>say $cities [ 2 ]; # Perl 6 too say @cities [ 2 ]; # turino </ul>
    67. 69. Same Container Type <ul>$cities = [ 'roma' , 'milano' , 'turino' ]; say $cities [ 2 ]; # $cities.WHAT say @cities [ 2 ]; # @cities.WHAT </ul>
    68. 70. Array Objects <ul>say $cities [ 2 ]; # Array() say @cities [ 2 ]; # Array() </ul>
    69. 71. Say Is Just A Method <ul>say $cities [ 2 ]; # turino @cities [ 2 ]. say ; # too </ul>
    70. 72. [ ] Too (Like Any Op) <ul>say $cities .[ 2 ]; # 2 is a parameter @cities .[ 2 ]. say ; # too </ul>
    71. 73. 2 == Last Index <ul>say $cities [ 2 ]; # turino say @cities [ 2 ]; # too </ul>
    72. 74. Perl 5 <ul>say $cities [ -1 ]; # turino say @cities [ 2 ]; # too </ul>
    73. 75. Perl 6 <ul>say $cities [ -1 ]; # turino say @cities [* -1 ]; # too </ul>
    74. 76. Whatever * <ul>say $cities [ -1 ]; # turino say @cities [*- 1 ]; # too #parameter – closure with 1 argument </ul>
    75. 77. Whatever * <ul>say $cities [ -1 ]; # turino say @cities [* / 2 ]; # milano </ul>
    76. 78. Whatever * <ul>say $cities [ -1 ]; # turino say @cities [*]; # roma milano turino </ul>
    77. 79. Whatever * <ul>say $cities [ -1 ]; # turino say @cities []; # roma milano turino # defaults to * </ul>
    78. 80. LoL <ul>say @cities [ 1 ][ 1 ]; </ul>
    79. 81. List Of List <ul>@cities = [< roma .. >], [< berlin .. >]; say @cities [ 1 ][ 1 ]; say $cities [ 1 ; 1 ]; </ul>
    80. 82. Let's Play A Game
    81. 83. Count the Smurfs
    82. 84. Count
    83. 85. Count <ul>How many elements does this list have? </ul>
    84. 86. Round 1
    85. 87. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; </ul>
    86. 88. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; # 4 my @number = ( 1 , 2 , 3 , 4 ); </ul>
    87. 89. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; # 4 my @number = ( 1 , 2 , 3 , 4 ); # 4 my @number = 1 , ( 2 , 3 ), 4 ; </ul>
    88. 90. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; # 4 my @number = ( 1 , 2 , 3 , 4 ); # 4 my @number = 1 , ( 2 , 3 ), 4 ; # 4 my @number = 1 , [ 2 , 3 ], 4 ; </ul>
    89. 91. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; # 4 my @number = ( 1 , 2 , 3 , 4 ); # 4 my @number = 1 , ( 2 , 3 ), 4 ; # 4 my @number = 1 , [ 2 , 3 ], 4 ; # 3 my @number = [ 1 , 2 , 3 , 4 ]; </ul>
    90. 92. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; # 4 my @number = ( 1 , 2 , 3 , 4 ); # 4 my @number = 1 , ( 2 , 3 ), 4 ; # 4 my @number = 1 , [ 2 , 3 ], 4 ; # 3 my @number = [ 1 , 2 , 3 , 4 ]; # 1 mysub 1 ,( 2 ,[ 3 , 4 ]), 5 ; # in @_ </ul>
    91. 93. How Many Elements ? <ul>my @number = 1 , 2 , 3 , 4 ; # 4 my @number = ( 1 , 2 , 3 , 4 ); # 4 my @number = 1 , ( 2 , 3 ), 4 ; # 4 my @number = 1 , [ 2 , 3 ], 4 ; # 3 my @number = [ 1 , 2 , 3 , 4 ]; # 1 mysub 1 ,( 2 ,[ 3 , 4 ]), 5 ; # 4 # all between name & ; </ul>
    92. 94. Round 2
    93. 95. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; </ul>
    94. 96. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; # 1 my $number = ( 1 , 2 , 3 , 4 ); </ul>
    95. 97. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; # 1 my $number = ( 1 , 2 , 3 , 4 ); # 4 my $number = 1 , ( 2 , 3 ), 4 ; </ul>
    96. 98. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; # 1 my $number = ( 1 , 2 , 3 , 4 ); # 4 my $number = 1 , ( 2 , 3 ), 4 ; # 1 my $number = ( 1 , 2 ), 3 , 4 ; </ul>
    97. 99. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; # 1 my $number = ( 1 , 2 , 3 , 4 ); # 4 my $number = 1 , ( 2 , 3 ), 4 ; # 1 my $number = ( 1 , 2 ), 3 , 4 ; # 2 my $number = ( 1 , [ 2 , 3 ], 4 ); </ul>
    98. 100. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; # 1 my $number = ( 1 , 2 , 3 , 4 ); # 4 my $number = 1 , ( 2 , 3 ), 4 ; # 1 my $number = ( 1 , 2 ), 3 , 4 ; # 2 my $number = ( 1 , [ 2 , 3 ], 4 ); # 3 my $number = [ 1 , 2 , 3 , 4 ]; </ul>
    99. 101. How Many Elements ? <ul>my $number = 1 , 2 , 3 , 4 ; # 1 my $number = ( 1 , 2 , 3 , 4 ); # 4 my $number = 1 , ( 2 , 3 ), 4 ; # 1 my $number = ( 1 , 2 ), 3 , 4 ; # 2 my $number = ( 1 , [ 2 , 3 ], 4 ); # 3 my $number = [ 1 , 2 , 3 , 4 ]; # 4 </ul>
    100. 102. Round 3
    101. 103. How Many Elements ? <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); </ul>
    102. 104. How Many Elements ? <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); @number = 1 , @pd , 4 ; </ul>
    103. 105. How Many Elements ? <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); @number = 1 , @pd , 4 ; # 6 @number = 1 , $pd , 4 ; </ul>
    104. 106. How Many Elements ? <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); @number = 1 , @pd , 4 ; # 6 @number = 1 , $pd , 4 ; # 3 @number = 1 , @pd . item , 4 ; </ul>
    105. 107. item & list = Conext Ops <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); @number = 1 , @pd , 4 ; # 6 @number = 1 , $pd , 4 ; # 3 @number = 1 , @pd . item , 4 ; # 3 @number = 1 , $pd . list , 4 ; </ul>
    106. 108. Nil = Nothing <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); @number = 1 , @pd , 4 ; # 6 @number = 1 , $pd , 4 ; # 3 @number = 1 , @pd . item , 4 ; # 3 @number = 1 , $pd . list , 4 ; # 6 @number = Nil , Nil , Nil ; </ul>
    107. 109. Nil = Nothing <ul>my $pd = my @pd = ( 3 , 1 , 4 , 1 ); @number = 1 , @pd , 4 ; # 6 @number = 1 , $pd , 4 ; # 3 @number = 1 , @pd . item , 4 ; # 3 @number = 1 , $pd . list , 4 ; # 6 @number = Nil , Nil , Nil ; # 0 </ul>
    108. 110. And The Winner Is ...
    109. 111. Perl 5 <ul>@digits = ( 4 ) x 5 ; # (4,4,4,4,4) </ul>
    110. 112. Perl 6 <ul>@digits = ( 4 ) x 5 ; # (4,4,4,4,4) @digits = 4 xx 5 ; # 4,4,4,4,4 </ul>
    111. 113. Multiply Strings <ul>@digits = 4 x 5 ; # '44444' @digits = 4 x 5 ; # '44444' </ul>
    112. 114. Multiply Strings <ul>@digits = 4 x 5 ; # '44444' @digits = ( 4 ) x 5 ; # '44444' </ul>
    113. 115. Multiply Strings <ul>@digits = '1 2' x 3 ; # '1 21 21 2' @digits = ( 1 , 2 ) x 3 ; # '1 21 21 2' </ul>
    114. 116. Multiply Lists <ul>@digits = ( 1 , 2 ) x 3 ; # 1,2,1,2,1,2 @digits = ( 1 , 2 ) xx 3 ; # 1,2,1,2,1,2 </ul>
    115. 117. Perl 5 <ul>@digits = ( 0 .. 9 ); # range op </ul>
    116. 118. Perl 5 & 6 <ul>@digits = ( 0 .. 9 ); </ul>
    117. 119. Perl 6 <ul>@digits = 0 .. 9 ; </ul>
    118. 120. Perl 6 <ul>@digits = ^ 10 ; # 0 .. 9 </ul>
    119. 121. 0 Is Given <ul>@digits = 0 ..^ 10 ; # 0 .. 9 </ul>
    120. 122. ^ Excludes The Range <ul>@digits = -1 ^..^ 10 ; # 0 .. 9 </ul>
    121. 123. Sequence Operator <ul>@digits = 0 ... 9 ; </ul>
    122. 124. Linear <ul>@digits = 0 ... 9 ; # 0 .. 9 </ul>
    123. 125. Arithmetic <ul>@digits = 0 ... 9 ; # 0 .. 9 @odd = 1 , 3 … 9 ; # 1,3,5,7,9 </ul>
    124. 126. Geometric <ul>@digits = 0 ... 9 ; # 0 .. 9 @odd = 1 , 3 … 9 ; # 1,3,5,7,9 @bin = 1 , 2 , 4 … 1024 ; #..,8,16,32,. </ul>
    125. 127. Fibonacci <ul>@digits = 0 ... 9 ; # 0 .. 9 @odd = 1 , 3 … 9 ; # 1,3,5,7,9 @bin = 1 , 2 , 4 … 1024 ; #..,8,16,32,. @fib = 0 , 1 ,*+* … 144 ; #..,1,2,3,.. </ul>
    126. 128. Watch Your Limit <ul>@odd = 1 , 3 … 10 ; # 1,3,.. * </ul>
    127. 129. Infinite List <ul>@odd = 1 , 3 … 10 ; # 1,3,.. * @number = 0 .. *; # 0 .. Inf </ul>
    128. 130. Certain Elements <ul>@odd = 1 , 3 … 10 ; # 1,3,.. * @number = 0 .. *; # 0 .. Inf say @odd [ 1 ]; # 3 say @number [ 5 ]; # 4 </ul>
    129. 131. All Elements <ul>@odd = 1 , 3 … 10 ; # 1,3,.. * @number = 0 .. *; # 0 .. Inf say @odd [*]; # waiting ... say @number ; # lots of digits </ul>
    130. 132. Number Of Elements <ul>@odd = 1 , 3 … 10 ; # 1,3,.. * @number = 0 .. *; # 0 .. Inf say + @odd ; # waiting ... say @number ; # lots of digits </ul>
    131. 133. What Happened? <ul>$number = 0 .. *; # 0 .. Inf say $number . WHAT ; # Range() </ul>
    132. 134. Guess Output? <ul>$number = 0 .. *; # 0 .. Inf say $number ; # ? </ul>
    133. 135. First Element <ul>$number = 0 .. *; # 0 .. Inf say $number ; # 0 </ul>
    134. 136. Infinite List <ul>$number = 0 .. *; # 0 .. Inf say @( $number ); # digits ... </ul>
    135. 137. Array <ul>@number = 0 .. *; # 0 .. Inf say @number [ 5 ]; </ul>
    136. 138. Generates As Needed <ul>@number = 0 .. *; # 0 .. Inf say @number [ 5 ]; # @number.reify(5) </ul>
    137. 139. Internal Representation <ul>@number = 0 .. *; # 0 .. Inf say @number . reify ( 5 ). perl ; # (0, 1, 2, 3, 4, 5, 6..*) </ul>
    138. 140. You Know These <ul>shift unshift push pop splice reverse map grep </ul>
    139. 141. Perl 5 <ul>%opera = ( 'verdi' => 'Aida' , 'puccini' => 'Turandot' , 'rossini' => 'Il barbiere' , ); </ul>
    140. 142. Perl 6 <ul>%opera = ( 'verdi' => 'Aida' , 'puccini' => 'Turandot' , 'rossini' => 'Il barbiere' , ); </ul>
    141. 143. No Grouping Needed <ul>%opera = 'verdi' => 'Aida' , 'puccini' => 'Turandot' , 'rossini' => 'Il barbiere' , ; </ul>
    142. 144. Still Hash Object <ul>%opera = 'verdi' => 'Aida' , 'puccini' => 'Turandot' , 'rossini' => 'Il barbiere' , ; %opera . WHAT eq 'Hash()' </ul>
    143. 145. New Pair Syntax <ul>%opera = : verdi ( 'Aida' ), : puccini ( 'Turandot' ), : rossini ( 'Il barbiere' ), ; %opera . WHAT eq 'Hash()' </ul>
    144. 146. With Autoquoting <ul>%opera = : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ; %opera . WHAT eq 'Hash()' </ul>
    145. 147. Item Context <ul>$opera = : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ; $opera . WHAT eq 'Pair()' </ul>
    146. 148. With Grouping <ul>$opera = ( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); %opera . WHAT eq 'Parcel()' </ul>
    147. 149. Parcel Know Positions <ul>$opera = ( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); 0 verdi Aida 1 puccini Turandot 2 rossini Il barbiere </ul>
    148. 150. Hash Context Op <ul>$opera = %( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); %opera . WHAT eq 'Hash()' </ul>
    149. 151. Hash Context Op <ul>$opera = hash( : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, ); %opera . WHAT eq 'Hash()' </ul>
    150. 152. Hash Generator Op <ul>$opera = { : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, }; %opera . WHAT eq 'Hash()' </ul>
    151. 153. Hash Generator Op <ul>%opera = { : verdi < Aida >, : puccini < Turandot >, : rossini < Il barbiere >, }; %opera . WHAT eq 'Hash()' </ul>
    152. 154. Invariant Sigils <ul>%opera { 'rossini' }; # Il barbiere </ul>
    153. 155. Invariant Sigils <ul>%opera .{ 'rossini' }; # alias .at_key() </ul>
    154. 156. Remember qw() ? <ul>%opera { 'rossini' }; # Il barbiere %opera < rossini >; </ul>
    155. 157. With Interpolation <ul>%opera { 'rossini' }; # Il barbiere %opera < rossini >; %opera << $autore >>; </ul>
    156. 158. Get 2 Operas <ul>%opera { 'rossini' , 'puccini' }; %opera < rossini puccini >; %opera << @autore >>; </ul>
    157. 159. Also Just Hashes <ul>$opera { 'rossini' , 'puccini' }; $opera < rossini puccini >; $opera << @autore >>; </ul>
    158. 160. Works On Parcel() Too <ul>$opera { 'rossini' , 'puccini' }; $opera < rossini puccini >; $opera << @autore >>; </ul>
    159. 161. Hash Methods <ul>%opera . keys ; # verdi puccini ro... %opera . values ; # aida turandot ... %opera . kv ; # verdi aida puccini ... </ul>
    160. 162. On Arrays Too <ul>@cities . keys ; # 0 1 2 @cities . values ; # roma milano ... @cities . kv ; # 0 roma 1 milano 2 ... </ul>
    161. 163. On Pairs <ul>$opera . key ; # rossini $opera . value ; # Il barbiere $opera . kv ; # </ul>
    162. 164. Other Hash Methods <ul>%opera . pairs ; # list of pair obj. %opera . exists ; # Bool %opera . delete ; # 1 | 0 </ul>
    163. 165. Other Methods <ul>%opera . pairs ; # list of pair obj. %opera . exists ; # one at a time %opera . delete ; # one at a time </ul>
    164. 166. Hash In Context <ul>? %opera ; # bool context + %opera ; # num context ~ %opera ; # string context </ul>
    165. 167. Hash In Context <ul>? %opera ; # Bool::True + %opera ; # 3 ~ %opera ; # rossini Il barbiere </ul>
    166. 168. Value In Context <ul>? %opera ; # Bool::True + %opera ; # 3 ~ %opera ; # rossini Il barbiere </ul>
    167. 169. New Hash Method <ul>say %opera . invert ; Aida verdi Turandot puccini Il barbiere rossini </ul>
    168. 170. Hash Generator <ul>my %h = @cities . classify ( { uc substr ( $_ , 0 , 1 ) } ); say %h ; $ R roma M milano T turino </ul>
    169. 171. Hash Generator <ul>@cities . categorize ({ catsub ( $_ ) }); say %h . perl ; </ul>
    170. 172. Hash Generator <ul>@cities . categorize ({ water ( $_ ) }); say %h . perl ; {&quot;mare&quot; => [&quot;roma&quot;], &quot;fiume&quot; => [&quot;roma&quot;, &quot;milano&quot;, &quot;turino&quot;], &quot;lago&quot; => Nil} </ul>
    171. 173. ==> <ul>Pipes </ul>
    172. 174. Schwartz. Transform <ul>@results = map {…}, sort {…}, map {...}, @input ; </ul>
    173. 175. Schwartz. Transform <ul>@results = map {…}, sort {…}, map {...}, @input ; @results = map {…} <== sort {…} <== map {…} <== @input ; </ul>
    174. 176. Schwartz. Transform <ul>@results = map {…}, sort {…}, map {...}, @input ; @results <== map {…} <== sort {…} <== map {…} <== @input ; </ul>
    175. 177. Schwartz. Transform <ul>@results = map {…}, sort {…}, map {...}, @input ; @input ==> map {…} ==> sort {…} ==> map {…} ==> @results ; </ul>
    176. 178. Metaops
    177. 179. Metaops <ul>= ! R </ul>
    178. 180. Metaops <ul>>> [ ] [ ] X Z S </ul>
    179. 181. Metaops <ul>>> [ ] [ ] X Z S </ul>
    180. 182. Hyperoperator <ul>>> </ul>
    181. 183. Hyperoperator <ul>>> .hyper() </ul>
    182. 184. Simple Example <ul>( 1 .. 5 ) >>++ </ul>
    183. 185. That Works <ul>@number >>++ </ul>
    184. 186. Result <ul>@number >>++ 2 , 3 , 4 , 5 , 6 </ul>
    185. 187. More Complicated <ul>( 1 .. 5 ) >>+>> 1 </ul>
    186. 188. Check Your Spaces <ul>(1..5) _ >>+>> _ 1 </ul>
    187. 189. Same Result <ul>( 1 .. 5 ) >>+>> 1 2 , 3 , 4 , 5 , 6 </ul>
    188. 190. Reverse Hyper <ul>( 1 .. 5 ) <<+<< 1 </ul>
    189. 191. Right Side Rules <ul>( 1 .. 5 ) <<+<< 1 2 </ul>
    190. 192. Both Rule ? <ul>( 1 .. 5 ) >>+<< 1 </ul>
    191. 193. Yes Both! <ul>( 1 .. 5 ) >>+<< 1 Runtime Error !!! </ul>
    192. 194. Preserves LoL ? <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+>> 1 </ul>
    193. 195. Preserves LoL ! <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+>> 1 2 , 3 , 4 , 5 , 6 , [ 7 , 8 , 9 , 10 ] </ul>
    194. 196. On 2 Sides ? <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<< ( 0 .. 4 , [ 1 .. 4 ]) </ul>
    195. 197. On 2 Sides ! <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<< ( 0 .. 4 , [ 1 .. 4 ]) ( 1 , 3 , 5 , 7 , 9 , [ 7 , 9 , 11 , 13 ]) </ul>
    196. 198. How About This? <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<< ( 0 .. 4 , [ 1 .. 5 ]) </ul>
    197. 199. Checks Lengths <ul>( 1 .. 5 , [ 6 .. 9 ]) >>+<< ( 0 .. 4 , [ 1 .. 5 ]) Runtime Error </ul>
    198. 200. Reduce <ul>[ ] .reduce </ul>
    199. 201. Do The Gauss <ul>[+] ( 1 .. 100 ) </ul>
    200. 202. Do The Gauss <ul>[+] ( 1 .. 100 ) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + ... </ul>
    201. 203. 100+1 * 50 <ul>[+] ( 1 .. 100 ) 5050 </ul>
    202. 204. Chained Comparsion <ul>[<] ( 1 .. 100 ) </ul>
    203. 205. Chained Comparsion <ul>[<] ( 1 .. 100 ) 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < ... </ul>
    204. 206. Chained Comparsion <ul>[<] ( 1 .. 100 ) Bool::True </ul>
    205. 207. Junction <ul>all ( 1 .. 100 ) > 0 </ul>
    206. 208. Junction <ul>all ( 1 .. 100 ) 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ... </ul>
    207. 209. Junction <ul>all ( 1 .. 100 ) > 0 ( True , True , True , True , ... </ul>
    208. 210. Bool Context <ul>? all ( 1 .. 100 ) > 0 True </ul>
    209. 211. Bool Context <ul>? all ( 1 .. 100 ) > 1 False </ul>
    210. 212. Metaops <ul>>> [ ] [ ] X Z S </ul>
    211. 213. Triangle <ul>[ ] triangle() </ul>
    212. 214. Back To Gauss <ul>[+] ( 1 .. 100 ) </ul>
    213. 215. Returns A List <ul>[+] ( 1 .. 100 ) ((((( 1 ) + 2 ) + 3 ) + 4 ) + 5 ) + 6 ) + ... </ul>
    214. 216. Returns A List <ul>[+] ( 1 .. 100 ) ( 1 , 3 , 6 , 10 , 15 , 21 , 28 , ... </ul>
    215. 217. Metaops <ul>>> [ ] [ ] X Z S </ul>
    216. 218. Cross <ul>.crosswith X </ul>
    217. 219. Cross <ul>( 1 , 2 ) X ( 1 , 2 ) 11 , 12 , 21 , 22 </ul>
    218. 220. Cross With Power <ul>( 1 , 2 ) X** ( 1 , 2 ) </ul>
    219. 221. Cross With Power <ul>( 1 , 2 ) X** ( 1 , 2 ) 1 , 1 , 2 , 4 </ul>
    220. 222. Metaops <ul>>> [ ] [ ] X Z S </ul>
    221. 223. Zip <ul>.zipwith() Z </ul>
    222. 224. Zip <ul>( 1 .. 10 ) Z < a .. j > < 1a 2b 3c 4d 5e 6f ...> </ul>
    223. 225. Zip <ul>for @a Z @b -> $a , $b { </ul>
    224. 226. Zip <ul>( 1 .. 4 ) Z+ ( 1 .. 4 ) </ul>
    225. 227. Zip <ul>( 1 .. 4 ) Z+ ( 1 .. 4 ) 2 , 4 , 6 , 8 </ul>
    226. 228. Metaops <ul>>> [ ] [ ] X Z S </ul>
    227. 229. Sequence <ul>.sequence S </ul>
    228. 230. __END__ ?
    229. 231. =begin END
    230. 232. Thank You

    ×