It Was Finally Christmas: Perl 6 Is Here!: Wim Vanderbauwhede School of Compu6ng Science University of Glasgow
It Was Finally Christmas: Perl 6 Is Here!: Wim Vanderbauwhede School of Compu6ng Science University of Glasgow
hZp://www.codeeval.com/
Context
Popularity of programming languages – TIOBE
hZps://github.com/rakudo/rakudo
VM (MoarVM)
• Meta-object protocol based
• Precise, genera6onal, and parallel GC
• First-class code objects, closures, …
• Excep6ons
• Con6nua6ons
• Threads, mutexes, …
• JIT compila6on
hZps://github.com/MoarVM/MoarVM
Grammars
Parsing
• Perl 6 has Grammars, Rules, Tokens and Regexes as
part of the language
• Similar to classes but used to organize parsers
• Rules are lexeme parsers
• Tokens are token parsers
• Regexes are PCREs
• Perl 6 is parsed and executed using a Perl 6-style
grammar.
Objects
Objects
JavaScript Python
Perl 6 Objects
Perl 6 Objects
Roles
Perl 6 Objects
• Accessors for free
• Default constructor
• Inheritance
• Roles (mixins)
• Built on a Meta Object Protocol
• Full introspec6on
• So s6ll nothing special …
But wait …
Perl 6 Objects
Perl 6 Objects
Gradual typing!
Gradual typing
• By default variables are dynamically typed.
• Explicitly typed variables are sta6cally typed.
• But type checks can be deferred to run 6me.
• Underlying theory:
hZps://github.com/samth/gradual-typing-bib
Gradual typing: subsets
• Type constraint checked at run 6me
Gradual typing: type capture
• Defer the specifica6on of a type constraint to the
6me the func6on is called.
• Allows to refer to a type both in the signature and
the func6on body.
Gradual typing: type capture
• Defer the specifica6on of a type constraint to the
6me the func6on is called.
• Allows to refer to a type both in the signature and
the func6on body.
Roles
Roles
• Basis for the Perl 6 type system
• Used for composi6on and mixins
• In Perl 6, the “funny characters” are syntax for a set
of predefined roles:
@: Posi6onal (array)
%: Associa6ve (hash)
&: Callable (subrou6ne)
• So …
No more funny characters!
• Actually, the “funny characters” are now op6onal:
Polymorphic func6ons
• Also known as mul6ple dispatch
Polymorphic func6ons
• Also known as mul6ple dispatch
Polymorphic func6ons
• Looks familiar?
Parametric roles
• Roles that take one or more type variables
Possibly Maybe
FuncHonal
programming
Func6onal features
• Higher-order func6ons
• Anonymous func6ons (lambdas)
• Currying
• Immutable lists, lazy evalua6on
• Tail call op6miza6on
• Op6onal immutable variables
Type capture revisited
• Type capture also works with closures and lambdas
Lazy lists
• Perl 6 dis6nguishes between sequences, lists and
arrays.
• Sequences are immutable, but are consumed
when iterated.
• Lists are immutable
• Arrays are mutable
• By defaults Seq, List and Array are lazy, but can be
made eager.
Seq and List
Array
Promises
Concurrency
• High-level
• Promises (futures)
• Channels
• Supplies
• Low-level
• Threads
• Schedulers
• Locks
Promises
Conclusion
•
Thank you!