Information AboutPerl 6 |
| CATEGORIES ABOUT PERL 6 | |
| perl | |
| upcoming software | |
|
Perl 6 is a planned major revision to the Perl Programming Language . Perl 6 introduces elements of many modern and historical languages. Perl 6 is not intended to be Backwards-compatible with earlier versions of Perl, though a Compatibility Mode is part of the specification. Perl 6 has been under development for over seven years, prompting some commentators to suggest that Perl 6 may be Vaporware . The Perl 6 project has never had a clear timeline, although various contributors have given estimates over the years. In early 2007 Jesse Vincent , the Perl 6 Project Manager said, "The Perl 6 project has no schedule ... one doesn't want to rush a largely volunteer effort to design and implement a worthy successor to Perl 5."1 There is currently a slow, but mostly complete, implementation written in the Haskell programming language called Pugs , and two alternative implementations exist, one based on Parrot and PGE and the other on Perl 5 . HISTORY The Perl 6 design process was first announced on July 19, 2000 , on day 4 of that year's Perl Conference ,2 by Larry Wall in his ''State of the Onion 2000'' talk.3 At that time, the primary goals were to remove "historical warts" from the language; "easy things should stay easy, hard things should get easier, and impossible things should get hard;" a general cleanup of the internal design and APIs. The process began with a series of Requests For Comments or "RFCs". This process was open to all contributors, and left no aspect of the language closed to change.4 Once the RFC process was complete, Wall reviewed and classified each request. He then began the process of writing the Apocalypses, the name of which refers to "a revealing" according to the first such document.5 While the original goal was to write one Apocalypse for each chapter of ''Programming Perl'', it became obvious that, as each Apocalypse was written, previous Apocalypses were being invalidated by later changes. For this reason, a set of Synopses were published, each one relating the contents of an Apocalypse, but with any subsequent changes reflected in updates. Today, Perl 6 specification continues almost entirely within the Synopses.6 There are also a series of Exegeses written by Damian Conway that explain the content of each Apocalypse in terms of practical usage. Each Exegesis consists of code examples along with discussion of the usage and implications of the examples.7 There are three primary methods of communication used in the development of Perl 6 today. The first is the #perl6 Source Code Repository used by the Pugs team. Pugs is an early implementation of Perl 6; see the Implementations section for more detail. As Of 2007 , Perl 6 was still under development, with no planned completion date. Goals The break in compatibility was mandated from the start of the project, and immediately allowed some of the changes that Larry Wall had suggested in his initial speech. "Historical warts" such as the confusion surrounding sigil usage for containers; the ambiguity between the select functions; the syntactic impact of bareword filehandles; and many other problems that Perl programmers had discussed fixing for years were some of the first issues addressed. Over the years, Perl 6 has undergone several alterations in its direction. The introduction of concepts from Python and Ruby were early influences, but as the pugs interpreter was written in the Haskell Programming Language , many Functional Programming influences were absorbed by the Perl 6 design team. IMPLEMENTATIONS Pugs is an implementation of Perl 6 written in Haskell . It is currently the closest thing to a full implementation of Perl 6. It will be used for Bootstrapping , providing a platform on which to write the Perl 6 compiler in Perl 6, and the test suite to validate it. This could, for example, involve translating the Pugs Haskell Source Code to Perl 6.9 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 to programmers using the language. For example, this would make it possible to extend the parser from within a program or library. Pugs can execute Perl 6 code directly, and has also compiled Perl 6 to JavaScript , Perl 5 and Parrot Bytecode . Lacking funding, even the key developer Audrey Tang is only working part time, so progress has not been as rapid as many wish. Parrot is a Virtual Machine designed for interpreted languages, primarily for Perl 6. The self-hosting Perl 6 compiler will (according to plan) target and also run on Parrot.1011 V6.pm is a pure Perl 5 implementation of Perl 6, making liberal use of existing CPAN modules, such as Moose and Pugs::Compiler::Rule. It aims to make the existing perl runtime a first-class virtual machine for both Perl 5 and Perl 6.12In 2007 , v6-MiniPerl6 ("mp6") and its reimplementation, v6-KindaPerl6 ("kp6") were written as a means to bootstrap the Perl-6.0.0 STD, using Perl 5. The STD is a full grammar for Perl 6, and is written in Perl 6. In theory, anything capable of parsing the STD and generating executable code is a suitable bootstrapping system for Perl 6. kp6 is currently compiled by mp6 and can work with multiple backends.1314 mp6 and kp6 are not full Perl 6 implementations, and are designed only to implement the minimum featureset required to bootstrap a full Perl 6 compiler. 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. Perl 5's documentation was regarded as excellent, even outside of the Perl community where even mixed reviews typically noted its maturity and breadth. However, if the documentation and the source code of the Perl 5 interpreter disagreed, the documentation was not considered authoritative, and 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.15 For example: my Int 3 = 0; my Num = 3.142; my Str = "Hello, world"; However, as with Perl 5, programmers can do most things without any explicit typing at all: my 3 = "25" + 10; # 3 is 35 Proponents of Static Typing claim that it is beneficial to compiler optimization, reducing programming errors and increasing maintainability, especially in large software projects. On the other hand, Dynamic Typing reduces input source code size, which is the bottleneck on smaller projects. It is helpful when writing quick Script s, One-liners or "one-off" code (i.e., code that is written to achieve some temporary purpose and will be run once). Perl 6 offers a hybrid typing system whereby the programmer may choose to use Static Typing, Dynamic Typing or mix the two. 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 were aliased into the elements of the array @_. If @_ were modified, the changes would be reflected in the original data. Perl 6 introduces true formal parameters to the language.16 In Perl 6, a subroutine declaration looks like this: sub do_something(Str , Int ) { ... } As in Perl 5, the formal parameters (i.e., the variables in the parameter list) are aliases to the actual parameters (the values passed in), but by default, the aliases are Constant so they cannot be modified. They may be declared explicitly as read-write aliases for the original value or as copies using the is rw or is copy directives should the programmer require them to be modified locally.Parameter passing modes Perl 6 provides three basic modes of parameter passing:
Here is an example of the use of all three parameter-passing modes:
somefunction(1, 2, :d<3>, 4, 5, 6); # =1, =2, Resource id #14=3, @e=(4,5,6) somefunction(:b<2>, :a<1>); # =1, =2 Positional parameters, such as those used above are always required, unless followed by ? to indicate that they are optional. Named parameters are optional by default, but may be marked as required by adding ! after the variable name. Slurpy parameters are ''always'' optional.Blocks and closures Parameters can also be passed to arbitrary blocks, which act as Closures . This is how, for example, for and while loop iterators are named. In the following example, a list is traversed, 3 elements at a time, and passed to the loop's block as the variables, , , .for @list -> (, , ) { ... } This is generally referred to as a "pointy sub" or "pointy block", and the arrow behaves almost exactly like the sub keyword, introducing an anonymous closure (or anonymous subroutine in Perl 5 terminology).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 = (1, 2, 3); my = $array {Link without Title} ; # equals 2 In Perl 6, sigils are invariant, which mean they do not change based on whether it is the array or the array element that is needed: # Perl 6 code my @array = (1, 2, 3); my = @array {Link without Title} ; # equals 2 The variance in Perl 5 was inspired by natural language: "The apple". # CORRECT "These apples. # CORRECT "The third one of the apples". # CORRECT "These third one of the apples". # WRONG The change in Perl 6 is meant to reduce the Cognitive Load of recognizing when to use the ''@'' or the ''$''. Object-oriented programming Perl 5 supported Object-oriented Programming via a mechanism known as ''blessing''. Any Reference could be blessed into being an object of a particular class, a blessed object could have Method s invoked on it using the "arrow syntax" which would cause Perl to locate or "dispatch" an appropriate Subroutine by name, and call it with the blessed variable 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 but supplies a more robust object model for the common cases.17 For example, a class to encapsulate a Cartesian Point could be defined and used this way: class Point is rw { has $.x; has $.y; } my Point .= new( :x<1.2>, :y<-3.7> ); # Now change x (note method "x" used as lvalue): .x = 2; say "Point is at X location: ", .x; The dot replaces the arrow in a nod to the many other languages (e.g. Java , Python , etc.) that have coalesced around dot as the syntax for method invocation. In the terminology of Perl 6, $.x is called an "attribute". Some languages call these fields or members. The method used to access an attribute is called an "accessor". Auto-accessors are methods that are created automatically, as the method x is in the example above. These accessor functions return the value of the attribute. When a class or individual attribute is declared with the is rw modifier (short for "read/write"), the auto-accessor can be passed a new value to set the attribute to, or it can be directly assigned to as an Lvalue (as in the example). Auto-accessors can be replaced by user-defined methods, should the programmer desire a richer interface to an attribute. Attributes can only be accessed directly from within a class definition. All other access must go through the accessor methods.Roles Roles in Perl 6 take on the function of both ''interfaces'' in Java and Traits 18 in Smalltalk variant Squeak . These are much like classes, but are entirely Abstract . These are used to perform composition when used with classes rather than adding to their Inheritance chain. Roles define nominal types; they provide semantic names for collections of behavior and state. The fundamental difference between a role and a class is that classes are instantiable; roles are not.19 Regular expressions See Also: Perl 6 rules Perl's Regular Expression and string-processing support has always been one of its defining features.20 Since Perl's pattern-matching constructs have exceeded the capabilities of Formal regular expressions for some time, Perl 6 documentation will exclusively refer to them as ''regexes'', distancing the term from the formal definition. Perl 6 provides a superset of Perl 5 features with respect to regexes, folding them into a larger framework called "rules" which provide the capabilities of Context-sensitive Parsing formalisms (such as the Syntactic Predicate s of Parsing Expression Grammar s and ANTLR ), as well as acting as a Closure with respect to their Lexical Scope .21 Rules are introduced with the rule keyword which has a usage quite similar to subroutine definition. Anonymous rules can also be introduced with the regex (or rx) keyword, or they can simply be used inline as regexps were in Perl 5 via the m (matching) or s (search and replace) operators.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 {Link without Title} 'real' language".22 Syntactic simplification Some Perl 5 constructs have been changed in Perl 6, optimized for different syntactic cues for the most common cases. For example, the parentheses (round Bracket s) required in Control Flow constructs in Perl 5 are now optional:23 if is_true() { for @array { ... } } Also, the , (comma) operator is now a list constructor, so enclosing parentheses are no longer required around lists. The code @array = 1, 2, 3, 4; now makes @array an array with exactly the elements '1', '2', '3', and '4'. Chained comparisons Perl 6 allows comparisons to "chain". That is, a sequence of comparisons such as the following are allowed: if C(20) <= <= C(25) { say "Room temperature!" } This is treated as if each left-to-right comparison were performed on its own, and the result is logically combined via the and operation.Lazy evaluation Perl 6 uses the technique of Lazy Evaluation of lists that has been a feature of some Functional Programming languages such as Haskell :24 @integers = 0..Inf; # integers from 0 to infinity The code above will not crash by attempting to assign a list of infinite size to the array @integers, nor will it hang indefinitely in attempting to expand the list if a limited number of slots are searched.This simplifies many common tasks in Perl 6 including input/output operations, list transformations and parameter passing. Junctions Perl 6 introduces the concept of ''junctions'': values that are composites of other values. In the earliest days of Perl 6's design, these were called "superpositions", by analogy to the concept in . While at first, such superpositional values seemed like merely a programmatic curiosity, over time their utility and intuitiveness became widely recognized, and junctions now occupy a central place in Perl 6's design. In their simplest form, junctions are created by combining a set of values with junctive Operator s: |
|
|