Perl-6

John Evans evansj at kilnar.com
Thu Jul 19 12:15:30 CDT 2001


Just a little article about the future of Perl-6. I thought I would pass
it along. I did snip all of the advertising garbage that came with the
email.


What is Perl-6?
By Andrew Johnson

If you interact with the Perl community (via usenet or various Web
sites) then you've probably heard about Perl-6 by now. But what exactly
is it? Just another step in the versioning scheme or something more? I
can't tell you exactly what Perl-6 will eventually look like, but I can
tell you what it is and why.

The change from Perl4 to Perl5 was essentially Larry Wall's rewrite of
Perl, and quite a bit was added to the Perl language at the time (but
not much of the Perl4 language was changed). Perl-6 is to be, in
Larry's words, "The community's rewrite of Perl".

Why rewrite Perl? Primarily, rewriting the core of perl (that's the
perl source code, not the Perl language) will make it cleaner, faster,
more extensible, easier for people to understand, and more accessible
to other people who can then participate in the maintenance and
development of perl itself. Larry also decided that there is no time
like the present to investigate changes to the language itself. What
isn't working out as well as we hoped? What additions would be useful?
Thus, the Perl6 RFC process began and the greater Perl community
submitted some 361 RFCs for language changes and/or additions.

Not all of the requests will be integrated into Perl-6 of course, but
Larry and the team of Perl-6 developers will sift through them and use
some in the new design. The process will take some time and you
shouldn't expect to see a usable Perl-6 for perhaps another year.
However, a few changes are apparent already:

    * Changing the usage of type symbols for variables
    * A new dereference operator (and concatenation operator)
    * Arrays and Hashes in scalar context
    * Typed variables?
    * Arrays and Hashes in scalar context

Changing the Usage of Type Symbols for Variables
Currently, as I'm sure you well know by now, we have three type symbols
for variables: $ for scalars, @ for arrays, and % for hashes. However,
you also know that these are symbols not strictly applied to variables,
but to the type of thing you want to access. For example, to obtain the
scalar value at index 3 of an array you use the $ symbol:

    print $array[3];

In Perl-6 these type symbols will be exclusively used with their
variable types, not the data type being accessed --- thus, the
following will be the correct syntax:

    $scalar = 12;
    @array  = (1,2,3);
    %hash   = (name => 'andrew', beer => 'dark ale');

    @slice  = @array[1,2];
    $scalar = @array[0];

    %hash{'age','children'} = (37, 2);
    print %hash{name};

As you can see, no matter what type of value you access you will use
the variable type symbol (no more using @ for slices of hashes, and $
for scalar access of single array or hash elements).

A New Dereference Operator (and Concatenation Operator)
The -> dereference arrow will be replaced with a dot (.). This makes
Perl more similar to other OO languages with respect to calling object
methods:

    $foo = SomeObject->new();
    $foo->some_method();

    # becomes:

    $foo = SomeObject.new();
    $foo.some_method();

This means that the dot will no longer be used as the concatenation
operator --- the new concat op will likely be the ~ character.

Typed Variables?
Yes, you will have the ability to declare variables as certain types
(such as 'int' or 'constant'), or dimensioning arrays to a certain
size. You won't be required to do this sort of thing, but it allows
perl to optimize the code if you do.

Arrays and Hashes in Scalar Context
When used in a scalar context, hashes and arrays will return a
reference to themselves. This means, to assign a reference to a hash or
array we can do the following:

    $a_ref = @array;
    $h_ref = %hash;

But, don't worry about your habit of getting the length (number of
elements) of an array by using it in scalar context, because now, an
array reference in numerical context will return its length, and will
return true if it holds any elements in a boolean context, so we can
still perform the same sorts of array testing as we do now.

As you can see even from this short foray, Perl-6 won't simply be
adding new stuff for us to use, but will be changing some of our
currently familiar syntax. This is not a bad thing. The changes
proposed so far make a good deal of sense and we should not fear them
merely because we will have to make some adjustments to they way we
currently do things. Also be aware that there will be some sort of
compatibility mode so that Perl-5 programs can still be run (not to
mention that versions of Perl-5 will not be disappearing anytime soon
either).

There is a good more information about Perl-6, and you can stay abreast
of its progress by checking out the following two sites:

    http://www.perl.org/perl6/
    http://dev.perl.org/perl6/

Next Week: Named parameters for subroutine calls.

About the author(s)
-------------------
Andrew Johnson lives in Winnipeg, Manitoba with his wife and two sons.
He works as a programmer/consultant and is the author of the recently
published "Elements of Programming with Perl" from Manning
Publications. Find the details at: http://members.home.net/perl-epwp/.
Beyond hacking around with Perl he enjoys reading, playing guitar,
camping, and a good dark ale. He can be reached at
andrew.johnson at unixinsider.com.
________________________________________________________________________________

ADDITIONAL RESOURCES

Online archive of Andrew Johnson's Perl newsletters
http://www.itworld.com/jump/perl_nl/members.home.net/andrew-johnson/perl/archit/perlarchive.html

Perl Mongers: Perl 6 Info
http://www.perl.org/perl6/

This Fortnight in Perl 6
http://www.perl.com/pub/a/2001/07/p6pdigest/20010703.html

Perl 6 To Be Complete Rewrite (But Not What You Think)
http://use.perl.org/article.pl?sid=00/07/19/161217


-- 
John Evans
http://evansj.kilnar.com/

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s++:- a- C+++>++++ ULSB++++$ P+++$ L++++$
E--- W++ N+ o? K? w O- M V PS+ !PE Y+ PGP t(--) 5-- X++(+++)
R+++ tv+ b+++(++++) DI+++ D++>+++ G+ e h--- r+++ y+++
------END GEEK CODE BLOCK------





More information about the Pikes-peak-pm mailing list