What’s new in Perl 6 (The short form) Dan Sugalski

Slides:



Advertisements
Similar presentations
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Advertisements

Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
OO in Parrot Dan Sugalski April 14, 2003.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
CSE 332: C++ exceptions Overview of C++ Exceptions Normal program control flow is halted –At the point where an exception is thrown The program call stack.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
Debugging Introduction to Computing Science and Programming I.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Hashes a “hash” is another fundamental data structure, like scalars and arrays. Hashes are sometimes called “associative arrays”. Basically, a hash associates.
29-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Subroutines. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc We’ll just say Subroutines. –“Functions” generally means built-in.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Exceptions. Many problems in code are handled when the code is compiled, but not all Some are impossible to catch before the program is run  Must run.
1 Web Based Programming Section 6 James King 12 August 2003.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Object Oriented Programming
1 Understanding Inheritance COSC 156 C++ Programming Lecture 8.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Perl 6 Update - PGE and Pugs Dr. Patrick R. Michaud April 26, 2005.
Control Structures. Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Exceptions Handling Exceptionally Sticky Problems.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
Perl Practical(?)‏ Extraction and Report Language.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
CS 105 Perl: Data Types Nathan Clement 15 May 2014.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
1 Using Yacc. 2 Introduction Grammar –CFG –Recursive Rules Shift/Reduce Parsing –See Figure 3-2. –LALR(1) –What Yacc Cannot Parse It cannot deal with.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Perl Chapter 6 Functions. Subprograms In Perl, all subprograms are functions – returns 0 or 1 value – although may have “side-effects” optional function.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
CS 105 Perl: Basic I/O, Context, Strings, Lists Nathan Clement January 22, 2014.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Coming up: Inheritance
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Introduction to Exceptions in Java CS201, SW Development Methods.
Built-In Functions. Notations For each function, I will give its name and prototype. –prototype = number and type of arguments ARRAY means an actual named.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
The Object-Oriented Thought Process Chapter 03
Information and Computer Sciences University of Hawaii, Manoa
Handling Exceptionally Sticky Problems
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Functions BIS1523 – Lecture 17.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Handling Exceptionally Sticky Problems
CISC101 Reminders Assignment 3 due today.
Design of the Parrot Virtual Machine The OO-ish bits
Presentation transcript:

What’s new in Perl 6 (The short form) Dan Sugalski

Important safety tips This is not quite final Larry may change his mind at any time, and has before I don’t do syntax

Biggest change first Dereference arrow is now the dot Concatenate is now the ~ Everyone can deal with this, I expect Liking it is optional

The New bits Variable notation Syntax fixes Control flow Regexes Objects

Variables preserve sigils Perl 5 $foo[1] “b”} Perl %foo{bar} %foo{“a”, “b”}

Why? Less confusion when you write code Lexer doesn’t need the changed sigil to figure out what’s going on Since the sigil is invariant, all the dereference dots are optional Was:$foo->[1]

Why? Less confusion when you write code Lexer doesn’t need the changed sigil to figure out what’s going on Since the sigil is invariant, all the dereference dots are optional Is:$foo.[1]

Why? Less confusion when you write code Lexer doesn’t need the changed sigil to figure out what’s going on Since the sigil is invariant, all the dereference dots are optional Can be:$foo[1]

References act as the = “Foo”; $bar print $bar[12]; Prints Foo Works for anything the reference points to The reference to the array acts as the array does Aggregates in scalar context return a reference

Typed Variables Typing is still optional! Declares what a variable returns and takes my The engine will use this to optimize for space and speed Can get fancier is Matrix of int; Syntax still up in the air a bit

Syntax Fixes Multi-way comparisons work $x <= 12 <= $y Logical operators properly propagate

All blocks are closures Well, they are Though often it doesn’t matter Makes it much easier to write your own version of perl’s control structures

Multiple dispatch Multiple subs and methods with the same name, differing only in their signature multi sub bar (Dog $foo) {…} multi sub bar (Cat $foo) {…} Engine dispatches based on the runtime signature of the sub or method call Requires explicit declarations Can’t happen by accident

~~ is the DWIM operator

~~ is the smart match operator Does The Right Thing (all 35 of them) based on the types of the left and right sides For true if an array ~~ /bar/ true if any entry in array matches %foo ~~ /bar/ true if any key matches $obj ~~ Class true if $obj isa Class

Built-in switch Like the CPAN SWITCH module, only moreso Uses ~~ DWIMmery

Built-in switch given ($foo) { when 1 {print “A number”} when “a” {print “A letter”} print “Trying plan B”; when /\b\w+\b/ {print “A word”} default {print “Dunno”} }

Real exception handling Catch exceptions with CATCH special block Just throw them in any try block try { CATCH {warn “Help!”} print 1 / 0; } The try’s actually optional You can when the exception object

Named parameters in subs You can now name the parameters to a subroutine or method sub some_sub ($foo, $bar) {…} When you call that sub or method, you can pass them by name or position some_sub(bar => 12, foo => 8); some_sub(“a”, “b”);

Curried functions Really a shorthand for named parameters Noted by a ^ between the sigil and variable name We sort them Unicodely, then substitute in For example, they lets us kill the global $a and = sort {$b cmp

Curried functions Really a shorthand for named parameters Noted by a ^ between the sigil and variable name We sort them Unicodely, then substitute in For example, they lets us kill the global $a and = sort {$^b cmp

Curried functions Really a shorthand for named parameters Noted by a ^ between the sigil and variable name We sort them Unicodely, then substitute in For example, they lets us kill the global $a and = sort {$^b cmp Work in closures too $foo = {print “Hi “, $^a}; $foo->(“Fred”); Prints Hi Fred

More parens are optional Don’t need them for if, while, or for Other than that, not a big deal You can still use them

For is fancier for is a bit different -> $baz {…} Works across multiple -> $x, $y {…} Runs until the end of the longest aggregate Short aggregates fill with undefs Counts don’t have to -> $x, $y, $z {…}

Hyper-operators Allow you to work on all the elements of an aggregate at once Noted by a »« (Or you can use >> and By default just iterates over the aggregates Overridable if you want to do Clever

Regexes Lots of changes here Regex engine is getting full lexing and parsing support (Everyone tries anyway, so we might as well do it right) Full object-oriented, inheritable, overridable grammar system

The Rationale Regexes started simply They definitely aren’t simple any more The wrong things are short Too much is wedged into that damn (?thingie) construct Annoying and it all looks the same Very bad

Big changes /x is now the default Modifiers move to the front Colon separates modifiers $foo =~ s:i/\bfred\b/Barney/; Or inside if you’d rather if ($bar =~ /:i \ba\w+\b/) { print “Word starting with A”} Variable-length lookbehind works

Syntax changes () capturing parens [] non-capturing parens {} closures that execute when control passes over them <> mark assertions : leads off metasyntactic things

Interpolation Changes $foo interpolates literally to interpolate as interpolates as an alternation interpolates alternations of regexes %foo matches against alternation of %foo’s keys

Useful new modifiers :p5 makes regex use perl 5 syntax :nth maches or substitutes the nth occurrence :nx matches n times :every when paired with :nth matches/substitutes every nth occurrence

Powerful enough to parse perl Perl 6 grammar is really a perl 6 grammar That means you can change it if you want Don’t like. for deref? Change it It’s OO, so just change the parts you want to If we can parse perl, we can parse anything

New object model Because almost anything’s better than what we have now Though it works out OK for Perl 5 and Python If you don’t poke it too hard…

Perl 6 style objects Much more structured than perl 5 objects Much more compile-time restricted Full hiding from parent and child classes Better dispatch control More introspection and overriability

Attributes Class-specific per-object data elements Only visible from within methods of the defining class May be exposed by lvalue methods (Though it’s still not direct access) Fixes, more or less, the fragile base class problem

Built-in delegation support Useful when subclassing classes with different core semantics (perl 5, Java, or.NET objects, for example) I have no idea how this will look It will work, though

Questions? ?