All Topics  
Perl 6

 

   Email Print
   Bookmark   Link






 

Perl 6



 
 
Perl 6 is a planned major revision to the Perl
Perl

In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language....
 programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
. It is a language specification which introduces elements of many modern and historical languages. Perl 6 is not intended to be backwards-compatible
Backward compatibility

In technology, for example in telecommunications and computing, a device or technology is said to be backwards compatible if it allows input generated by older devices....
 with earlier versions of Perl, though a compatibility mode
Compatibility mode

A compatibility mode is a software mechanism in which a computer's operating system emulates an older central processing unit, operating system, and/or Platform in order to allow obsolete software to remain compatible with the computer's newer hardware or software....
 is part of the specification.

Perl 6 has been in development since 2000. The Perl 6 project has never had a clear timeline, although various contributors have given estimates over the years.






Discussion
Ask a question about 'Perl 6'
Start a new discussion about 'Perl 6'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Perl 6 is a planned major revision to the Perl
Perl

In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language....
 programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
. It is a language specification which introduces elements of many modern and historical languages. Perl 6 is not intended to be backwards-compatible
Backward compatibility

In technology, for example in telecommunications and computing, a device or technology is said to be backwards compatible if it allows input generated by older devices....
 with earlier versions of Perl, though a compatibility mode
Compatibility mode

A compatibility mode is a software mechanism in which a computer's operating system emulates an older central processing unit, operating system, and/or Platform in order to allow obsolete software to remain compatible with the computer's newer hardware or software....
 is part of the specification.

Perl 6 has been in development since 2000. 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."

There are currently two implementation projects of Perl 6 underway, Rakudo Perl and Pugs. Rakudo Perl
Rakudo Perl

Rakudo Perl is an implementation of the Perl 6 specification for the Parrot virtual machine, currently in Software development. The Rakudo Perl development team issues regular monthly releases, but the Trunk available from the Git repository, a distributed revision control system, incorporates the latest Patch and features....
 is based on Parrot
Parrot virtual machine

Parrot is a register machine virtual machine being developed using the C and intended to run dynamic languages efficiently. It uses just-in-time compilation for speed to reduce the interpretation overhead....
 and PGE, and Pugs
Pugs

Pugs is a compiler and interpreter for the Perl 6 programming language, started on February 1 2005 by Audrey Tang....
 is written in Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
.

History


The Perl 6 design process was first announced on July 19, 2000, on day 4 of that year's Perl Conference
O'Reilly Open Source Convention

The O'Reilly Open Source Convention is an annual Convention for the discussion of free and open source software. It is organized by the publisher O'Reilly Media and is held each summer in the United States....
, by Larry Wall
Larry Wall

Larry Wall is a programmer and author, most widely known for his creation of the Perl programming language in 1987....
 in his State of the Onion 2000 talk. 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
Request for Comments

In computer network engineering, a request for comments is a memorandum published by the Internet Engineering Task Force describing methods, behaviors, research, or innovations applicable to the working of the Internet and Internet-connected systems....
 or "RFCs". This process was open to all contributors, and left no aspect of the language closed to change.

Once the RFC process was complete, Wall reviewed and classified each request. He then began the process of writing several "Apocalypse
Apocalypse

Apocalypse is a term applied to the disclosure to certain privileged persons of something hidden from the majority of humankind. Today the term is often used to refer to the Doomsday event, which may be a shortening of the phrase apokalupsis eschaton which literally means "revelation at the end of the ?on, or age"....
s", a term which means "revealing." 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.

There are also a series of Exegeses written by Damian Conway
Damian Conway

Damian Conway is a prominent member of the Perl community, a proponent of object-oriented programming, and the author of #Books. He is also an Associate Professor in the Faculty of Information Technology at Monash University....
 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.

There are three primary methods of communication used in the development of Perl 6 today. The first is the [irc://irc.freenode.net/#perl6 #perl6] IRC channel
Internet Relay Chat

Internet Relay Chat is a form of real-time Internet text messaging or synchronous conferencing. It is mainly designed for Many-to-many in discussion forums, called #Channels, but also allows One-to-one via instant messaging, as well as chat and data transfers via Direct Client-to-Client....
 on freenode
Freenode

freenode, formerly known as Open Projects Network, is a popular Internet Relay Chat computer network used to discuss peer-directed projects....
. The second is a set of mailing list
Mailing list

A mailing list is a collection of names and addresses used by an individual or an organization to send material to multiple recipients. The term is often extended to include the people subscribed to such a list, so the group of subscribers is referred to as "the mailing list", or simply "the list"....
s on The Perl Foundation
The Perl Foundation

The Perl Foundation is dedicated to the advancement of the Perl programming language through open discussion, collaboration, design, and code. The Perl Foundation is a non-profit organization, 501 organization based in Grand Ledge, Michigan....
's servers at . The third is the Subversion source code repository used by the pugs
Pugs

Pugs is a compiler and interpreter for the Perl 6 programming language, started on February 1 2005 by Audrey Tang....
 team. Pugs is an early implementation of Perl 6; see the Implementations section for more detail.

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
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
 and Ruby were early influences, but as the pugs interpreter was written in the Haskell programming language
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
, many functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 influences were absorbed by the Perl 6 design team.

Implementations

, multiple Perl 6 implementations are under development, but none are considered "complete". As noted in the history section the language design itself is still subject to change.

Rakudo Perl
Rakudo Perl

Rakudo Perl is an implementation of the Perl 6 specification for the Parrot virtual machine, currently in Software development. The Rakudo Perl development team issues regular monthly releases, but the Trunk available from the Git repository, a distributed revision control system, incorporates the latest Patch and features....
  is a Perl 6 implementation targeting the Parrot virtual machine
Parrot virtual machine

Parrot is a register machine virtual machine being developed using the C and intended to run dynamic languages efficiently. It uses just-in-time compilation for speed to reduce the interpretation overhead....
. Parrot
Parrot virtual machine

Parrot is a register machine virtual machine being developed using the C and intended to run dynamic languages efficiently. It uses just-in-time compilation for speed to reduce the interpretation overhead....
 is a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
 designed for dynamic languages, primarily for Perl 6. It provides several powerful compiler tools, many of which take inspiration from Perl 6. In particular, the Parrot Grammar Engine, or PGE, provides an implementation of Perl 6 grammars. As well, the language used for building compilers is itself Not Quite Perl 6, or NQP. The Rakudo implementation of Perl 6 on Parrot takes advantage of PGE and NQP. Some portions of Rakudo are written in Perl 6 itself, though this is not a self-hosting implementation, nor are there concrete plans at this point to make Rakudo a bootstrapping compiler.

Pugs is an implementation of Perl 6 written in Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
. It will be used for bootstrapping
Bootstrapping (compilers)

Bootstrapping is a term used in computer science to describe the techniques involved in writing a compiler in the target programming language which it is intended to compile....
, 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
Source code

In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language....
 to Perl 6. After that, Perl 6 will be self-hosted
Self-hosting

The term self-hosting was coined to refer to the use of a computer program as part of the toolchain or operating system that produces new versions of that same program?for example, a compiler that can compile its own source code....
—it will be used to compile
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 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
JavaScript

JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard....
, Perl 5
Perl

In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language....
 and Parrot
Parrot virtual machine

Parrot is a register machine virtual machine being developed using the C and intended to run dynamic languages efficiently. It uses just-in-time compilation for speed to reduce the interpretation overhead....
 bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
. Lacking funding, even the key developer Audrey Tang
Audrey Tang

Audrey Tang is a Taiwanese people free software programmer, who has been described as one of the "ten greats of Taiwanese computing."...
 is only working part time, so progress has not been as rapid as many wish.

v6.pm
V6 (Perl)

v6 is a Perl module which runs under Perl version 5, and transforms Perl 6 code into Perl 5 code on the fly. To quote the release notes:...
is a pure Perl 5 implementation of Perl 6, making liberal use of existing CPAN
CPAN

CPAN, the Comprehensive Perl Archive Network, is an archive of over 14,800 modules of software written in Perl, as well as documentation for it....
 modules, such as Moose and PugsCompilerRule. It aims to make the existing perl runtime a first-class virtual machine for both Perl 5 and Perl 6.

In 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. 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 is regarded as excellent, even outside of the Perl community where even mixed reviews typically note its maturity and breadth. However, since the documentation is not considered authoritative and only describes the behaviour of the actual Perl 5 interpreter informally, any discrepancies found between the documentation and the implementation may lead to either being changed to reflect the other.

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 $i = 0; my Num $n = 3.142; my Str $s = "Hello, world"; However, as with Perl 5, programmers can do most things without any explicit typing at all: my $i = "25" + 10; # $i is 35

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
Parameter (computer science)

In computer programming, a parameter is a special kind of variable#In_computer_programming that refers to data that a subroutine receives to operate on....
 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 the elements of @_ were modified, the changes would be reflected in the original data.

Perl 6 introduces true formal parameters to the language. In Perl 6, a subroutine declaration looks like this:

sub do_something(Str $thing, Int $other)

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
Variable

A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e....
 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:
  • Positional
  • Named
  • Slurpy
Positional parameters are the typical ordered list of parameters that most programming languages use. All parameters may also be passed by using their name in an unordered way. A named-only parameter can only be passed by specifying its name (that is, it never captures a positional argument), and are indicated with a leading : character. Slurpy parameters (indicated by an * before the parameter name) are Perl 6's tool for creating variadic function
Variadic function

In computer programming, a variadic function is a function of variable arity; that is, one which can take different numbers of arguments. Support for variadic functions differs widely among programming languages....
s. A slurpy hash will capture remaining passed-by-name parameters, whereas a slurpy array will capture remaining passed-by-position parameters.

Here is an example of the use of all three parameter-passing modes:

sub somefunction($a, $b, :$c, :$d, *@e)

somefunction(1, 2, :d<3>, 4, 5, 6); # $a=1, $b=2, $d=3, @e=(4,5,6) somefunction(:b<2>, :a<1>); # $a=1, $b=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
Closure (computer science)

In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables....
. 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, $a, $b, $c.

for @list -> ($a, $b, $c)

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
Sigil (computer programming)

In computer programming, a sigil is a symbol attached to a variable name, showing the variable's datatype or Scope . The term was first applied to Perl usage by Philip Gwyn in 1999 to replace the more cumbersome "funny character in front of a variable name"....
 — 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 $element = $array[1]; # $element 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 $element = @array[1]; # $element equals 2

The variance in Perl 5 was inspired by number agreement in English and many other natural languages:

"This apple." # CORRECT "These apples." # CORRECT "This third apple." # CORRECT "These third apple." # WRONG

The change in Perl 6 is meant to reduce the cognitive load
Cognitive load

Cognitive Load is a term that refers to the load on working memory during instruction.Instruction may be aimed at teaching learners problem solving skills, thinking and reasoning skills Many would agree that people learn better when they can build on what they already understand , but the more a person has to learn in a shorter amount of...
 of recognizing when to use the @ or the $.

Object-oriented programming

Perl 5 supported object-oriented programming
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
 via a mechanism known as blessing. Any reference
Reference (computer science)

In computer science, a reference is an object containing information about how to locate and access the particular data item, as opposed to containing the data itself....
 could be blessed into being an object of a particular class, a blessed object could have method
Method (computer science)

In object-oriented programming, a method is a subroutine that is exclusively associated either with a class or with an object . Like a procedure in procedural programming languages, a method usually consists of a sequence of statement to perform an action, a set of input parameter to customize those actions, and possibly an output value...
s invoked on it using the "arrow syntax" which would cause Perl to locate or "dispatch" an appropriate subroutine
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
 by name, and call it with the blessed variable as its first argument.

While extremely powerful—virtually any other computer language's object model
Object model

In computing, object model has two related but distinct meanings:# The properties of object in general, in a specific computer programming language, technology, notation or methodology that uses them....
 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. For example, a class to encapsulate a Cartesian
Cartesian coordinate system

In mathematics, the Cartesian coordinate system is used to determine each Point uniquely in a Plane through two numbers, usually called the x-coordinate or abscissa and the y-coordinate or ordinate of the point....
 point
Point (geometry)

In geometry, topology and related branches of mathematics a spatial point describes a specific object within a given space that consists of neither volume, area, length, nor any other higher dimensional analogue....
 could be defined and used this way:

class Point is rw

my Point $point .= new( :x<1.2>, :y<-3.7> );

# Now change x (note method "x" used as lvalue): $point.x = 2; say "Point is at X location: ", $point.x;

The dot replaces the arrow in a nod to the many other languages (e.g. Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
, 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 interfaces in Java
Interface (Java)

An interface in the Java is an abstract type that is used to specify an interface that class must implement. Interfaces are declared using the interface Java keywords, and may only contain Method signatures and constant declarations ....
, mixin
Mixin

In object-oriented programming languages, a mixin is a class that provides a certain functionality to be Inheritance by a subclass, but is not meant to stand alone....
s
in Ruby, and traits
Trait (abstract type)

In computer programming, a trait is an abstract type, used as a "simple conceptual model for structuring object oriented programs". Traits are similar to mixins, but may include definitions for class methods....
 in the Smalltalk
Smalltalk

Smalltalk is an Object-oriented programming, Type system, reflection computer programming programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human?computer symbiosis." It was designed and created in part for educational use, more so for constructionist learning, at PARC by Al...
 variant Squeak
Squeak

The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers....
. These are much like classes, but are entirely abstract
Abstraction (computer science)

In computer science, abstraction is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time....
. These are used to perform composition when used with classes rather than adding to their inheritance
Inheritance (computer science)

In object-oriented programming, inheritance is a way to form new class es using classes that have already been defined. The inheritance concept was invented in 1967 for Simula....
 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.

Essentially, a role is a bundle of (possibly abstract) methods and attributes that can be added to a class without using inheritance. A role can even be added to an individual object; in this case, Perl 6 will create an anonymous subclass, add the role to the subclass, and change the object's class to the anonymous subclass.

For example, a Dog
Dog

The dog is a domesticated subspecies of the Gray Wolf, a member of the Canidae family of the order Carnivora. The term is used for both feral and pet varieties....
 is a Mammal
Mammal

Mammals are a class of vertebrate animals whose name is derived from their distinctive feature, mammary glands, with which they feed their young....
. Dogs inherit certain characteristics from Mammals, such as mammary gland
Mammary gland

Mammary glands are the organ s that, in mammals, produce milk for the sustenance of the young. These exocrine glands are enlarged and modified sweat glands and give mammals their name....
s and (through Mammal's parent, Vertebrate
Vertebrate

Vertebrates are members of the subphylum Vertebrata, chordates with Vertebras or Vertebral columns. The grouping sometimes includes the hagfish, which have no vertebrae, but are genetically quite closely related to lampreys, which do have vertebrae....
) a backbone
Backbone

Backbone may mean:* Vertebral column, of a vertebrate organism* Backbone chain, in polymer chemistry, the framework of the molecule* Backbone Entertainment, a video game development company...
. Dogs may have one of several distinct types of behavior; for example, a Dog may be a Pet
PET

The term pet typically refers to a pet.PET may also refer to:...
, a Stray
Feral

A feral organism is one that has escaped from domestication and returned, partly or wholly, to its wildlife state. The introduction of feral animals or plants, like any introduced species, can disrupt ecosystems and may, in some cases, contribute to extinction of indigenous species....
, or a Guide
Guide dog

Guide dogs are assistance dogs trained to lead blindness or Visual impairment people around obstacles.Although the dogs can be trained to navigate various obstacles, they are partially color blind and are not capable of interpreting street signs....
 for the blind. However, these are simply sets of additional behaviors that can be added to a Dog; a Cat
Cat

The cat , also known as the Domestication cat or house cat to distinguish it from other Felinae and Felidae, is a small predationy carnivore species of crepuscular mammal that is valued by humans for its companionship and its ability to hunt vermin, snakes, scorpions, and other unwanted household pests....
 can equally be a Pet or Stray, for example. Hence, Dog and Mammal are classes, while Pet, Stray, and Guide are roles.

class Mammal is Vertebrate class Dog is Mammal role Pet role Stray role Guide

Roles are added to a class or object with the does keyword, as opposed to inheritance's is. The keywords reflect the differing meanings of the two features: role composition gives a class the behavior of the role, but doesn't indicate that it is truly the same thing as the role.

class GuideDog is Dog does Guide # Subclass composes role

my $dog = new Dog; $dog does Guide; # Individual object composes role

Although roles are distinct from classes, both are types, so a role can appear in a variable declaration where one would normally put a class. For example, a Blind role for a Human could include an attribute of type Guide; this attribute could contain a Guide Dog, a Guide Horse
Guide horse

A guide horse is an experimental mobility option for blind people who do not wish to or cannot use a guide dog. They are provided by The Guide Horse Foundation, founded in 1999 to provide miniature horses as assistance dogs to blind users living in rural environments....
, a Guide Human, or even a Guide Machine.

class Human role Blind

Regular expressions

Perl's regular expression
Regular expression

In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters....
 and string-processing support has always been one of its defining features. Since Perl's pattern-matching constructs have exceeded the capabilities of regular language
Regular language

In theoretical computer science, a regular language is a formal language that satisfies the following equivalent properties:* it can be accepted by a deterministic finite state machine...
 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
Context-sensitive

Context-sensitive is an adjective meaning "depending on context" or "depending on circumstances".See:* Context-sensitive grammar* Context-sensitive language...
 parsing
Parsing

In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a sequence of lexical analysis#Token to determine their grammatical structure with respect to a given formal grammar....
 formalisms (such as the syntactic predicate
Syntactic predicate

A syntactic predicate specifies the syntactic validity of applying a production in a formal grammar and is analogous to a semantic predicate that specifies the semantic validity of applying a production....
s of parsing expression grammar
Parsing expression grammar

A parsing expression grammar, or PEG, is a type of analytic grammar formal grammar that describes a formal language in terms of a set of rules for recognizing string in the language....
s and ANTLR
ANTLR

In computer based language recognition, ANother Tool for Language Recognition is the name of a parser generator that uses LL parser parsing. ANTLR is the successor to the Purdue Compiler Construction Tool Set , first developed in 1989, and is under active development....
), as well as acting as a closure
Closure (computer science)

In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables....
 with respect to their lexical scope
Scope (programming)

In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes....
. 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 (substitute) operators.

In , 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".

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
Bracket

Brackets are punctuation marks used in pairs to set apart or interject text within other text. In computer science, the term is sometimes said to strictly apply to the square or box type....
s) required in control flow
Control flow

In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated....
 constructs in Perl 5 are now optional:

if is_true

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) <= $temperature <= C(25)

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
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 of lists that has been a feature of some functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 languages such as Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
:

@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 quantum physics of quantum superposition
Quantum superposition

Quantum superposition is the fundamental law of quantum mechanics. It defines the allowed state space of a quantum mechanical system.In Probability theory, every possible event has a non-negative real number between zero and one associated to it, the probability, which gives the chance that it happens....
s — waveforms that can simultaneously occupy several states until observation "collapses" them. A Perl 5 module released in 2000 by Damian Conway
Damian Conway

Damian Conway is a prominent member of the Perl community, a proponent of object-oriented programming, and the author of #Books. He is also an Associate Professor in the Faculty of Information Technology at Monash University....
 called QuantumSuperpositions provided an initial proof of concept
Proof of concept

Proof of concept is a short and/or incomplete realization of a certain method or idea to demonstrate its feasibility, or a demonstration in principle, whose purpose is to verify that some concept or theory is probably capable of exploitation in a useful manner....
. 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
Operator (programming)

Programming languages generally support a set of operators that are similar to operator. A language may contain a fixed number of built-in operators or it may allow the creation of programmer-defined operators ....
s:

my $any_even_digit = 0|2|4|6|8; # any(0, 2, 4, 6, 8) my $all_odd_digits = 1&3&5&7&9; # all(1, 3, 5, 7, 9)

| indicates a value which is equal to either its left or right-hand arguments. & indicates a value which is equal to both its left and right-hand arguments. These values can be used in any code that would use a normal value. Operations performed on a junction act on all members of the junction equally, and combine according to the junctive operator. So, ("apple"|"banana") ~ "s" would yield "apples"|"bananas". In comparisons, junctions return a single true or false result for the comparison. "any" junctions return true if the comparison is true for any one of the elements of the junction. "all" junctions return true if the comparison is true for all of the elements of the junction.

Junctions can also be used to more richly augment the type system by introducing a style of generic programming
Generic programming

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983....
 that is constrained to junctions of types:

sub get_tint ( RGB_Color|CMYK_Color $color, num $opacity) sub store_record (Record&Storable $rec)

Autothreading
Junctions are unordered; 1|2|3 and 3|2|1 represent the same value. This lack of ordering means that the Perl 6 compiler can choose to evaluate junctive expressions in parallel. For instance, the code:

for all(@array)

would indicate to the compiler that the for loop should be run in parallel, possibly in separate threads
Thread (computer science)

In computer science, a thread of execution is a Fork of a computer program into two or more Concurrency running task s. The implementation of threads and process es differs from one operating system to another, but in most cases, a thread is contained inside a process....
. This feature is dubbed "autothreading"; its usage and implementation is not finalized and is a matter of debate in the development community.

Macros

In low-level languages, the concept of macros has become synonymous with textual substitution of source-code due to the widespread use of the C preprocessor
C preprocessor

The C preprocessor is the preprocessor for the C . In many C implementations, it is a separate computer program invoked by the compiler as the first part of translation....
. However, high-level languages such as Lisp
Lisp programming language

Lisp is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older....
 pre-dated C in their use of macros that were far more powerful. It is this Lisp-like macro concept that Perl 6 will take advantage of. The power of this sort of macro stems from the fact that it operates on the program as a high-level data structure
Data structure

A data structure in computer science is a way of storing data in a computer so that it can be used efficiently. It is an organization of mathematical and logical concepts of data....
, rather than as simple text, and has the full capabilities of the programming language at its disposal.

A Perl 6 macro definition will look like a subroutine or method definition, and can operate on unparsed strings, an AST
Abstract syntax tree

In computer science, an abstract syntax tree , or just syntax tree, is a directed tree representation of the abstract syntactic structure of source code written in a certain programming language....
 representing pre-parsed code, or a combination of the two. A macro definition would look like this:

macro hello($what)

In this particular example, the macro is no more complex than a C-style textual substitution, but because parsing of the macro parameter occurs before the macro operates on the calling code, diagnostic messages would be far more informative. However, because the body of a macro is executed at compile time
Compile time

In computer science, compile time refers to either the operations performed by a compiler , programming language requirements that must be met by source code for it to be successfully compiled , or properties of the program that can be reasoned about at compile time....
 each time it is used, many techniques of optimization
Optimization (computer science)

In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less Computer data storage or other resources, or draw less power....
 can be employed. It is even possible to entirely eliminate complex computations from resulting programs by performing the work at compile-time.

Hello world

The hello world program
Hello world program

A "Hello World" program is a computer program that prints out "Hello world!" on a display device. It is used in many introductory tutorials for teaching a programming language....
 is a common program used to introduce a language. In Perl 6, hello world is:

say 'Hello, world'

— though there is more than one way to do it
There is more than one way to do it

There's more than one way to do it is a Perl motto. The language was designed with this idea in mind, so that it "doesn't try to tell the programmer how to program"....
. The say function prints its arguments (like the print function) with a trailing newline
Newline

In computing, a newline is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line?that is, on the next line below the text, immediately proceeding the newline....
. (This feature was backported into Perl 5.10.)

External links


Specification

  • . The Synopses (The official language specification). While the Apocalypses and Exegeses are linked here for reference, note that the Synopses are kept very much more up-to-date and are the primary recommended reference.
  • - For historical interest only.


Implementations

  • - A current implementation of Perl 6, written in Haskell
    Haskell (programming language)

    Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
    .
  • - A pure-perl implementation, based on a .
  • - The main site for Parrot
    Parrot virtual machine

    Parrot is a register machine virtual machine being developed using the C and intended to run dynamic languages efficiently. It uses just-in-time compilation for speed to reduce the interpretation overhead....
     development.


Other

- Perl 6's blogs aggregrator. - resources catalog - Larry Wall's talk about Perl 5 and Perl 6 at Open Source Developer Conference 2006 in Netanya
Netanya

Netanya is a city in the Center District of Israel and is the capital of the Sharon plain. It is located between the 'Poleg' stream and Wingate Institute in the south and the 'Avichail' stream in the north....
, Israel (archived HTML, with links to slides and audio recording) - Answers a wide range of questions about Perl 6. - A step-by-step guide to writing and running your first Perl 6 program. An independent perl6 wiki.