Information AboutPerl 6 |
| CATEGORIES ABOUT PERL 6 | |
| perl | |
| upcoming software | |
|
Perl 6 is not intended to be backwards-compatible, though there will be a compatibility mode. Larry Wall , the creator of Perl, has called Perl 6 "the community's rewrite of Perl", because he has based the changes largely on 361 "requests for change" submitted by the Perl community in 2000 . He is outlining these changes in a series of long essays, called Apocalypses, which are numbered to correspond to chapters in '' Programming Perl '' ("The Camel Book"). The current, unfinalized, specification of Perl 6 is encapsulated in design documents called Synopses, which are numbered to correspond to Apocalypses. IMPLEMENTATIONS Pugs is an implementation of Perl 6 in the Haskell Programming Language that will be used for Bootstrapping . Pugs's goal is to write the Perl 6 compiler in Perl 6 itself, possibly by translating its source code to Perl 6. After that, Perl 6 will be Self-hosted —it will be used to Compile itself. Much of the implementation of Perl will then be exposed, making it possible to, for example, extend the parser. Pugs can execute Perl 6 code directly, as well as compile Perl 6 to JavaScript , Perl 5 or Parrot Bytecode . Parrot is a Virtual Machine designed for interpreted languages, primarily for Perl 6. The self-hosting Perl 6 compiler will target (and also run on) Parrot. MAJOR CHANGES FROM PERL 5 Perl 5 and Perl 6 differ fundamentally, though in general the intent has been to "keep Perl 6 Perl". Most of the changes are intended to normalize the language, to make it easier for learning and expert programmers alike to understand, and to make "easy things easier and hard things more possible". A Specification A major, but non-technical difference between Perl 5 and Perl 6 is that Perl 6 began as a specification. This means that Perl 6 can be re-implemented if needed, and it also means that programmers don't have to read the source code for the ultimate authority on any given feature. While Perl 5's documentation was regarded as excellent, even outside of the Perl community {Link without Title} , if the documentation and the source code of the Perl 5 interpreter disagreed, the documentation would be changed. A Type System In Perl 6, the Dynamic Type System of Perl 5 has been augmented by the addition of static types. For example: my int 3 = 0; my num = 3.141; my str = "Hello, world"; However, as with Perl 5, programmers can do most things without any explicit typing at all: my 3 = "25" + 10; Static typing is beneficial for reducing subtle errors and increasing maintainability, especially in large software projects. But static typing is a burden when writing quick Script s, One-liner s or "one-off" code (i.e., code that is written to achieve some temporary purpose, run once and retired), purposes that have long been a mainstay of Perl. A currently unresolved debate in the Perl 6 design community regards how code written without types interacts with code using types. Formal Subroutine Parameter Lists Perl 5 defined subroutines without Formal Parameter lists at all (though simple parameter counting and some very loose type checking can be done using Perl 5's "prototypes"). Subroutine arguments passed in became aliases into elements of the array @_. If @_ were modified, the changes would be reflected in the original data: # Perl 5 code sub incr { ++ } my = 1; incr(); # is now 2 incr(3); # runtime error: "Modification of a read-only value attempted" Perl 6 introduces true formal parameters to the language. In Perl 6, a subroutine declaration looks something like this: sub do_something(Str , Int ) { ... } As in Perl 5, the formal parameters (i.e., the pseudo-variables in the parameter list) are aliases to the actual parameters (the values passed in), but by default, the aliases are marked is readonly (meaning similar to Constant ) so they cannot be modified: sub incr(Num ) { ++; # compile-time error } If a formal parameter is followed by is copy or is rw, however, it ''can'' be modified. In the is copy case, Perl 6 copies the actual parameter's data rather than aliasing it; so it can be modified, but changes are local to the subroutine. In the is rw case (rw stands for "read-write"), the alias is not marked readonly. This change also catches at ''compile-time'' errors such as the one above: sub incr(Num is rw) { ++ } incr(3); #compile-time error There are a number of features in parameter lists which make parameter passing much more powerful than in Perl 5:
For example: sub my_split(Rule ? = rx/\s+/, Str ? = , Int ? where $^lim >= 0) { ... } Sigil invariance In Perl 5, ''sigils'' —the punctuation characters that precede a variable name—changed depending on how the variable was used: # Perl 5 code my @array = (0, 1, 2, 3); my = $array {Link without Title} ; # equals 1 In Perl 6, sigils are invariant: my @array = (0, 1, 2, 3); my = @array {Link without Title} ; # equals 1 This change is meant to reduce the Cognitive Load of recognizing that a variable spelled ... is actually the variable @array.Object orientation Perl 5 supported Object Orientation via a mechanism known as ''blessing''. Any Reference could be blessed into being an object of a particular class, as so: # Perl 5 code my = bless , 'Class'; A blessed object could then have Method s invoked on it using the "arrow syntax": # Perl 5 code ->method(); which would cause Perl to locate ("dispatch") an appropriate Subroutine named method, and call it with as its first argument.While extremely powerful—virtually any other computer language's object model could be simulated using this simple facility—it made the most common case of object orientation, a Struct -like object with some associated code, unnecessarily difficult. In addition, because Perl could make no assumptions about the object model in use, method invocation could not be optimized very well. In the spirit of making the "easy things easy but hard things possible", Perl 6 retains the blessing model for programmers who desire unusual behavior, but supplies a more robust object model for the common cases. For example, a class to encapsulate a Cartesian Point could be written: class Point is rw { has $.x; has $.y; } and then used: my Point .= new; .x = 1.2; .y = -3.7; The dot replaces the arrow in a nod to the many other languages, e.g. C++ , Java , Python , and Ruby , that have coalesced around dot as the syntax for method invocation. Note that the methods " x" and "y" are not explicitly declared. They are called auto-accessors. The "is rw" modifier on the class definition allows all of its public member attributes to be writable by default, using the auto-accessors. {Link without Title} Attributes may be declared in the following ways: has $.a; # default accessor mode (usually read only) has $.b is rw; # Read/write accessor has $!c; # No public accessor (private) has Resource id #14; # Same as $!d Regular expressions Perl's Regular Expression and string-processing support has always been one of its defining features. Unlike most other languages, in which regular expressions are provided by a Library , Perl has Pattern Matching facilities built-in to the language. Since Perl's pattern-matching construct has exceeded the capabilities of Formal regular expressions for some time, regular expressions have been renamed ''regexes'' (no longer an abbreviation of ''regular expressions''). In Apocalypse 5 , Larry Wall enumerated 20 problems with "current regex culture". Among these were that Perl's regexes were "too compact and 'cute'", had "too much reliance on too few metacharacters", "little support for named captures", "little support for grammars", and "poor integration with [the] 'real' language". He then proceeded to lay out what were then the most radical changes to the language yet. It may be most telling that there are only six ''unchanged'' features from Perl 5's regexes:
  |
Rx { A
| "" class="copylinks" target="_blank">b c ( d e ) f : g } |
  |
My |
02468 # any(0, 2, 4, 6, 8) |
  |
My |
123 |
  |
+ |
4 # junction now equals 567 |
  |
+ |
(1&2) # junction now equals (678)&(789) |
  |
Sub Get Tint (RGB ColorCMYK Color , Num Where 0 < |
$^opacity <= 1) { } |
  |
Junctions Are Unordered <code>123</code> And <code>321</code> Represent The Same Value This Lack Of Ordering Means That The Perl 6 Compiler Can Choose To Evaluate Junctive Expressions ''in Parallel'' In Fact, Many In The Perl 6 Community Believe That Junctions Could Supersede Explicit
| "http://wwwinformationdelightinfo/encyclopedia/entry/Thread_(computer_science)" class="copylinks">Multithreading as the ordinary way to achieve Parallelism in Perl 6 For instance, the code |
|
|
|