Perl6 and Parrot

 

 

 

Intro to rewrite of perl¡K why?

 

New perl6 features

 

Parrot compiler

 

WHOI perl software contribution site

 

 


perl6  is the next major version of perl

 

 

It's a complete rewrite and significant update.

 

 

It's a work in progress and won't be available until

          probably 2006.  But you can follow the progress

          and try out new features in beta.

 

 

Along with perl6 is the development of Parrot

         A new engine that will run perl6 as well as a number of

                    other interpreters (more later)

        

 

Why the rewrite?

 

        perl was getting too large and complex

                maintenance was becoming a chore

                adding new features was too hard

 

 

Goals for perl6

 

           support for new features

                     may change the way you code, but aren't required

           cleaner

           faster

           easier to use

           flexible enough to allow for future changes

           Modularize so other languages can use features, like regex engine!


 

Architectural Considerations

 

           perl6 will still be perl

 

                     easy to write to get the job done fast and easily

                     fundamental syntax is still the same

                              but a little more consistent

                     mechanically translatable from perl5

                            (but will eventually disappear

                               use perl5ish   pragma

                               #!/usr/bin/perl5

                    All the good stuff from perl5 will be alive in perl6

 

 

           New features

 

                   exceptions

                   delegation

                   continuations

                   co-routines

                   currying

                   Huh?? 

 

                   powerful features that the average user won't use

                   But prepares perl for the future  

 

 

          Long term usability

 

               want strong, dependable tools with room to grow

 

   

        Development of perl6 has helped perl5

               Latest version is perl5.8  (last stable one was v5.6)

               Can expect more releases.

               Perl6 will be backward compatible (with switches)

               Can now (with v5.8) use some features of perl6 (use perl6ish;)


 

          Other considerations

 

                  Perl's parser will be written in perl (perl5!)

                           using perl's regular expressions

 

               

                 The perl compiler/interpreter systems will be designed so

                         they can emit C, Java, .NET, C# and other languages

                         It will run on small devices, like palm.

 

                 The system for extending perl with C and C++ will be

                         replaced with a better, easier system

 

                            write C subs that can be called as perl subroutines

 

                Will support more low level programming features,

                           specify types for variables

                           bit-wise features for integers and strings

                          

 

                Will also support more high-level programming

                          functional programming

                          OOP  features

 

                 

                         

 

 


 

Simple example of some changes in perl6

 

 

                     # PERL5

 

                    while ($line =  <> )   {

                           @elt = split(" ", $line);

                           $elt[0] =~ s/abc/x/;

                           $count{$elt[1]}++;

                    }

 

                    foreach (sort  keys  %count) {

                          print "$_    $count {$_} \n";

                    }

 

 

 

 

                     # same code in PERL6

 

                    while ($line =  <$ARGS> )   {               # diamond operator

                           @elt = split(" ", $line);

                           @elt[0] ~~ s/abc/x/;                     # arrays always use @

                           %count{ @elt[1] }++;                   #  all hashes use %

                    }

 

                    foreach (sort  %count) {                        # does the right thing

                          print "$_    %count {$_} \n";            #  hash!

                    }

 

 

 

               


Other new features¡K

 

               Some operator renaming

 

-> becomes .  (like the rest of the world)

. becomes ~  (stitch)

 

etc¡K

 

 

               New operators

 

                      // is like || except it tests the left side for definedness

                      ^^  is xor

                     

                      etc¡K

 

                vector operators

 

                    >>  <<   are used to denote "list operations" which work on

                          all elements of an array or list

 

                                    (3,8,2,9,3,8) >>-<< 1;            # ((2,7,1,8,2,7)

 

                 junctive operators

 

                      A junctive is a single value that is equivalent to multiple

                        values

 

                               1|2|3 + 4;      # 5|6|7

                               if $roll == 1|2|3    {  print "Low roll\n";  }

 

                  Chained comparisons

 

                         if  3  < $roll <=6    { print "High roll\n" }

 


 

                  Binding

 

                         my  $y  :=  $x;                     # both are bound

                         $y = "hello, world";

                         print "$x";                            # prints hello world

 

 

                 Piping operators

==> and <== are akin to unix pipes

 

                    @result = map  {  $_ * 8}

                                             grep {  /^ \d+  $/ }

                                                  @data;

 

                     @data ==> grep { /^ \d+ $/}

==> map {$_ * 8}

==> @result;

 

                     @result <== map {$_ *8}

                                     <== grep { /^ \d+ $/}

                                      <== @data;

 

                   zip

                        interleaves the elements of multiple arrays

 

                       for  zip (@names,@codes)  -> $name,$zipcode  {

                               print "name: $name;   Zip code: $zipcode\n";

                       }

 

 

 


   New statements

 

                  many new programming features, like try, BEGIN, when, ¡K

 

 

                   for example:    given/when is like a case statement, but

                   much more powerful.

 

                          given  $val  {

                               when 'A4'   {  print "2 characters"}

                                when %B4  { print "hash key $val is defined" }

                                when /C4/    { die  "contains C4!"  }

                                when &D4  { print "returned true"}

                           }

 

                    Can use when without given, since when tests on $_

 

                    for (@events)  {

                              when Mouse::Over                { change_focus($_) }

                              when Mouse::Click                { make_selection()  }

                              when Window::Close     { delete_window()   }

                              when /unknown/            { log_event}$_)      }

                    }

 

                   It¡¦s just a nice  if-elsif-else  construct¡K

                                   

        


Regular expressions

 

                Regular expressions are being extended and will be known

                as 'rules'. Gives much more control over pattern matching.

 

                There is a constructor  rx that constructs a pattern object

                 or rule that can be saved for later.

 

                                   $rule =  rx  /abc/  ;

 

                A few of the new pattern elements

                        

                             ^      start of string

                             ^^    start of line

                              $      end of line

                             $$     end of line

                              <sp>    space

                              <ws>   whitespace  (same as \s+)

                              \n          newline

                              \N         not a newline

 

                              #       Comment.  Rules ignore whitespace, must specify

<>    Assertion identifiers

          <n>    match exactly n times

          <m..n> match at least m, but no more than m

          <m..n>?   minimal match m to n times

                             

                              many others¡K

 

                 also regex modifiers to control length of match and number

                  of matches.

 

                                   $r = rx  :(3)  /abc/;      # match abc 3 times

 

                   Include a predefined rule

 

                                   $line ~~ /<$rule>/;          # =~ is now ~~

 

Parrot Project

 

Parrot is strongly related to perl6 but is not perl6

 

The plan is to separate the interpreter from the parser/compiler

          with a virtual machine. Other examples of virtual machines

          are JVM and Microsoft¡¦s .NET initiative.

 

         A VM will allow diverse computers all to run the same software.

 

Perl system execution

 

 Source code <-> parser <-> compiler (to bytecode) <->optimizer <-> runtime

 

   Right now all these routines are embedded in perl. Perl6 will separate them.

 

Why Parrot?   Parrot¡¦s implementation (register based not stack based) is more powerful/faster version than the others.

 

                  Speed is paramount concern

                  Stability is extremely important

                  Flexibility is also a concern

 

To see what¡¦s happened with parrot development

 

                          www.parrotcode.org

 

Parrot is much more complete than perl6 since it was needed first before the perl rewrite.

 

Perl6 will still execute as always¡K       Myprog.plx  Infiles

   All compilation/optimization will happen in background.

   Can keep intermediate files, if wanted.

 

Other languages using parrot

 

   Python, BASIC, forth, Scheme (lisp), Ruby (OO scripting), miniperl,

Cola (Java), Jako (C), even befunge and Ook!

 

 

 

 

 

 

Perl contributed software

 

Steve Lerner, Chris Hammond and I started up a perl archive site

     (also with the help of adam shepard)

 

Site contains programs and snippets of code to use and study

 

Anyone can contribute, anyone can use them

    (well, must be in whoi.edu domain to get them..)

 

              http://www.whoi.edu/internal/software_contributions

             

 

This is the first of many archives that may be implemented

                      matlab utilities

                      web  utilities

                         :

                     

Very new so some bugs still need to be worked out.  Send problems/comments to

 

 soft-contrib@whoi.edu

 

 

This site is not supported (well, very little) nor funded.  It was kindly

created from an idea by Steve, Chris and me.  More volunteers are welcome!

More contributions are welcome!