SlideShare a Scribd company logo

Perl6 signatures

Slides from my talk at London Perl Mongers on 2018-03-22 covering Perl6 Signatures in detail. Special bonus slides for Type Checking and Multi methods.

Perl6 signatures

Slides from my talk at London Perl Mongers on 2018-03-22 covering Perl6 Signatures in detail. Special bonus slides for Type Checking and Multi methods.

Perl6 signatures

1 of 19
Download to read offline
Perl6 Signatures
Everything you didn’t realise you wanted to know,
and a whole lot more!
No Signature
sub foo {
@_.say;
}
● Should be familiar to Perl devs
● All arguments put into lexical @_ array
● @_ array only populated with arguments in this case
No Signature (Note)
sub foo {
@_.say;
}
foo( A => 1 );
*ERRORS*
foo( ( A => 1 ) );
[A => 1]
When calling a sub (or method)
a Pair using either
A => 1 or :A(1) syntax will be
treated as a named argument.
Empty Signature
sub foo() {
say “I take orders from no one”;
}
● Specifically states this subroutine takes no arguments.
● Will error (generally at compile time) if called with arguments.
● Not just constants : eg. outer scope, state declarations
Empty Signature (methods)
method foo() {
say self.bar;
}
● Methods with an empty signature also error if called with
arguments.
● Have access to self (and the $ alias) though.
Positional Arguments
sub foo($a,$b,$c) {
say “$a : $b : $c”;
}
● Maps arguments to lexical variables based on position
● Errors unless the exact number of arguments are passed

Recommended

Perl6 signatures, types and multicall
Perl6 signatures, types and multicallPerl6 signatures, types and multicall
Perl6 signatures, types and multicallSimon Proctor
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular ExpressionsMukesh Tekwani
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)Chirag Shetty
 

More Related Content

What's hot

Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrepTri Truong
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,filesShankar D
 
Php basics
Php basicsPhp basics
Php basicshamfu
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsingsanchi29
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingGuido Wachsmuth
 
Strings in Python
Strings in PythonStrings in Python
Strings in Pythonnitamhaske
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesEelco Visser
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netProgrammer Blog
 
String variable in php
String variable in phpString variable in php
String variable in phpchantholnet
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedGuido Wachsmuth
 
Processing Regex Python
Processing Regex PythonProcessing Regex Python
Processing Regex Pythonprimeteacher32
 
python Function
python Function python Function
python Function Ronak Rathi
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 

What's hot (20)

Antlr V3
Antlr V3Antlr V3
Antlr V3
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,files
 
Php basics
Php basicsPhp basics
Php basics
 
Intoduction to php strings
Intoduction to php  stringsIntoduction to php  strings
Intoduction to php strings
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 
Operator precedance parsing
Operator precedance parsingOperator precedance parsing
Operator precedance parsing
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.net
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 
String variable in php
String variable in phpString variable in php
String variable in php
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
 
Formal Grammars
Formal GrammarsFormal Grammars
Formal Grammars
 
Processing Regex Python
Processing Regex PythonProcessing Regex Python
Processing Regex Python
 
python Function
python Function python Function
python Function
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 

Similar to Perl6 signatures

Similar to Perl6 signatures (20)

ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Practical approach to perl day2
Practical approach to perl day2Practical approach to perl day2
Practical approach to perl day2
 
Apache pig
Apache pigApache pig
Apache pig
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)
 
Hadoop Pig
Hadoop PigHadoop Pig
Hadoop Pig
 
Es6 to es5
Es6 to es5Es6 to es5
Es6 to es5
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
Subroutines
SubroutinesSubroutines
Subroutines
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Haskell Jumpstart
Haskell JumpstartHaskell Jumpstart
Haskell Jumpstart
 
Functions in python3
Functions in python3Functions in python3
Functions in python3
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 

More from Simon Proctor

An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to RakuSimon Proctor
 
Building a raku module
Building a raku moduleBuilding a raku module
Building a raku moduleSimon Proctor
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperatorsSimon Proctor
 
Perl 6 command line scripting
Perl 6 command line scriptingPerl 6 command line scripting
Perl 6 command line scriptingSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 

More from Simon Proctor (9)

An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to Raku
 
Building a raku module
Building a raku moduleBuilding a raku module
Building a raku module
 
Multi stage docker
Multi stage dockerMulti stage docker
Multi stage docker
 
Phasers to stunning
Phasers to stunningPhasers to stunning
Phasers to stunning
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperators
 
24 uses for perl6
24 uses for perl624 uses for perl6
24 uses for perl6
 
Perl 6 command line scripting
Perl 6 command line scriptingPerl 6 command line scripting
Perl 6 command line scripting
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 

Recently uploaded

BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdfBOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdfMichaelOLeary82
 
Mainframe Sort Operations: Gaining the Insights You Need for Peak Performance
Mainframe Sort Operations: Gaining the Insights You Need for Peak PerformanceMainframe Sort Operations: Gaining the Insights You Need for Peak Performance
Mainframe Sort Operations: Gaining the Insights You Need for Peak PerformancePrecisely
 
Embracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You GrowEmbracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You GrowPaul Balogh
 
Christmas Coding
Christmas CodingChristmas Coding
Christmas CodingGDSC PJATK
 
Smartphone-Based Teaching System for Neonate Soothing Motions
Smartphone-Based Teaching System for Neonate Soothing MotionsSmartphone-Based Teaching System for Neonate Soothing Motions
Smartphone-Based Teaching System for Neonate Soothing Motionssugiuralab
 
American Horror Story research powerpoint
American Horror Story research powerpointAmerican Horror Story research powerpoint
American Horror Story research powerpoint17pmat213
 
Blockchain Interoperability
Blockchain InteroperabilityBlockchain Interoperability
Blockchain InteroperabilityLiveplex
 
GM Series Detailed service manual 6864115B62-C.pdf
GM Series Detailed service manual 6864115B62-C.pdfGM Series Detailed service manual 6864115B62-C.pdf
GM Series Detailed service manual 6864115B62-C.pdfFajarHarianto5
 
Correcting Common Mistakes, AsyncAwait.pptx
Correcting Common Mistakes, AsyncAwait.pptxCorrecting Common Mistakes, AsyncAwait.pptx
Correcting Common Mistakes, AsyncAwait.pptxBrandon Minnick, MBA
 
Charting New Waters: Data Integration Excellence for Port & Marine Operations
Charting New Waters: Data Integration Excellence for Port & Marine OperationsCharting New Waters: Data Integration Excellence for Port & Marine Operations
Charting New Waters: Data Integration Excellence for Port & Marine Operationsmarketing932765
 
Three-S Retail Automation (AcilimSoft Product)
Three-S Retail Automation (AcilimSoft Product)Three-S Retail Automation (AcilimSoft Product)
Three-S Retail Automation (AcilimSoft Product)Mustafa Kuğu
 
Transcript: New stores, new views: Booksellers adapting engaging and thriving...
Transcript: New stores, new views: Booksellers adapting engaging and thriving...Transcript: New stores, new views: Booksellers adapting engaging and thriving...
Transcript: New stores, new views: Booksellers adapting engaging and thriving...BookNet Canada
 
CenturyDX-IT-Company
CenturyDX-IT-CompanyCenturyDX-IT-Company
CenturyDX-IT-CompanyMustafa Kuğu
 
WEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITY
WEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITYWEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITY
WEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITYLiveplex
 
Dataliva Company Brief 2024
Dataliva Company Brief 2024Dataliva Company Brief 2024
Dataliva Company Brief 2024Mustafa Kuğu
 
Intra-body nano-network - Brief summary by Mik Andersen
Intra-body nano-network - Brief summary by Mik AndersenIntra-body nano-network - Brief summary by Mik Andersen
Intra-body nano-network - Brief summary by Mik Andersenkrcdnsqxswifzizvzs
 
The Umbrella Academy conventions analysis
The Umbrella Academy conventions analysisThe Umbrella Academy conventions analysis
The Umbrella Academy conventions analysis17cmat022
 
Stage 1 Tradecraft
Stage 1 TradecraftStage 1 Tradecraft
Stage 1 Tradecraftmatt806068
 
Go Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdfGo Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdfNho Vĩnh
 
Journey to Google
Journey to GoogleJourney to Google
Journey to GoogleGDSC PJATK
 

Recently uploaded (20)

BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdfBOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
 
Mainframe Sort Operations: Gaining the Insights You Need for Peak Performance
Mainframe Sort Operations: Gaining the Insights You Need for Peak PerformanceMainframe Sort Operations: Gaining the Insights You Need for Peak Performance
Mainframe Sort Operations: Gaining the Insights You Need for Peak Performance
 
Embracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You GrowEmbracing Disruption: Adding a Bit of Chaos to Help You Grow
Embracing Disruption: Adding a Bit of Chaos to Help You Grow
 
Christmas Coding
Christmas CodingChristmas Coding
Christmas Coding
 
Smartphone-Based Teaching System for Neonate Soothing Motions
Smartphone-Based Teaching System for Neonate Soothing MotionsSmartphone-Based Teaching System for Neonate Soothing Motions
Smartphone-Based Teaching System for Neonate Soothing Motions
 
American Horror Story research powerpoint
American Horror Story research powerpointAmerican Horror Story research powerpoint
American Horror Story research powerpoint
 
Blockchain Interoperability
Blockchain InteroperabilityBlockchain Interoperability
Blockchain Interoperability
 
GM Series Detailed service manual 6864115B62-C.pdf
GM Series Detailed service manual 6864115B62-C.pdfGM Series Detailed service manual 6864115B62-C.pdf
GM Series Detailed service manual 6864115B62-C.pdf
 
Correcting Common Mistakes, AsyncAwait.pptx
Correcting Common Mistakes, AsyncAwait.pptxCorrecting Common Mistakes, AsyncAwait.pptx
Correcting Common Mistakes, AsyncAwait.pptx
 
Charting New Waters: Data Integration Excellence for Port & Marine Operations
Charting New Waters: Data Integration Excellence for Port & Marine OperationsCharting New Waters: Data Integration Excellence for Port & Marine Operations
Charting New Waters: Data Integration Excellence for Port & Marine Operations
 
Three-S Retail Automation (AcilimSoft Product)
Three-S Retail Automation (AcilimSoft Product)Three-S Retail Automation (AcilimSoft Product)
Three-S Retail Automation (AcilimSoft Product)
 
Transcript: New stores, new views: Booksellers adapting engaging and thriving...
Transcript: New stores, new views: Booksellers adapting engaging and thriving...Transcript: New stores, new views: Booksellers adapting engaging and thriving...
Transcript: New stores, new views: Booksellers adapting engaging and thriving...
 
CenturyDX-IT-Company
CenturyDX-IT-CompanyCenturyDX-IT-Company
CenturyDX-IT-Company
 
WEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITY
WEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITYWEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITY
WEB 3.0 & IDENTITY: THE NEW ERA OF DIGITAL IDENTITY
 
Dataliva Company Brief 2024
Dataliva Company Brief 2024Dataliva Company Brief 2024
Dataliva Company Brief 2024
 
Intra-body nano-network - Brief summary by Mik Andersen
Intra-body nano-network - Brief summary by Mik AndersenIntra-body nano-network - Brief summary by Mik Andersen
Intra-body nano-network - Brief summary by Mik Andersen
 
The Umbrella Academy conventions analysis
The Umbrella Academy conventions analysisThe Umbrella Academy conventions analysis
The Umbrella Academy conventions analysis
 
Stage 1 Tradecraft
Stage 1 TradecraftStage 1 Tradecraft
Stage 1 Tradecraft
 
Go Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdfGo Programming by Example_ Nho Vĩnh Share.pdf
Go Programming by Example_ Nho Vĩnh Share.pdf
 
Journey to Google
Journey to GoogleJourney to Google
Journey to Google
 

Perl6 signatures

  • 1. Perl6 Signatures Everything you didn’t realise you wanted to know, and a whole lot more!
  • 2. No Signature sub foo { @_.say; } ● Should be familiar to Perl devs ● All arguments put into lexical @_ array ● @_ array only populated with arguments in this case
  • 3. No Signature (Note) sub foo { @_.say; } foo( A => 1 ); *ERRORS* foo( ( A => 1 ) ); [A => 1] When calling a sub (or method) a Pair using either A => 1 or :A(1) syntax will be treated as a named argument.
  • 4. Empty Signature sub foo() { say “I take orders from no one”; } ● Specifically states this subroutine takes no arguments. ● Will error (generally at compile time) if called with arguments. ● Not just constants : eg. outer scope, state declarations
  • 5. Empty Signature (methods) method foo() { say self.bar; } ● Methods with an empty signature also error if called with arguments. ● Have access to self (and the $ alias) though.
  • 6. Positional Arguments sub foo($a,$b,$c) { say “$a : $b : $c”; } ● Maps arguments to lexical variables based on position ● Errors unless the exact number of arguments are passed
  • 7. Positional Arguments (methods) method foo($foo: $a) { say “{$foo.attr} : $a”; } ● Optional initial argument separated with : defines another reference for self that can be used in the method ● Useful with where clauses and multi methods ● Also can be used to specify class methods
  • 8. Positional Arguments : Defaults and optional sub foo($a,$b?,$c = 5) { say “$a : $b : $c”; } foo(1,2) 1 : 2 : 5 ● Any positions not filled will get their defaults ● Mark an argument as optional with ? after the name.
  • 9. Positional Arguments : Sigils sub foo(@a) { say @a; } foo(1,2) Errors foo( [1,2] ) [1,2] @ and % sigils are type signifiers for Positional and Associative roles.
  • 10. Positional Arguments : Flattening Slurpy sub foo(*@a) { say @a; } foo(1,2) [1,2] foo( 1,[2,3] ) [1,2,3] Single * will slurp and flatten all remaining positional arguments. foo(1,(2,3)) [1,2,3] foo(1,{2 => 3}) [1,{2=>3}]
  • 11. Positional Arguments : Non Flattening Slurpy sub foo(**@a) { say @a; } foo(1,2) [1,2] foo( 1,[2,3] ) [1,[2,3]] Double * will slurp all remaining positional arguments but not flatten lists or hashes. foo(1,(1,2)) [1,(1,2)] foo(1,{2 => 3}) [1,{2=>3}]
  • 12. Positional Arguments : Single Rule Slurpy sub foo(+@a) { say @a; } foo(1) [1] foo( [2,3] ) [2,3] A + slurpy will flatten a single iterable object into the arguments array. Otherwise it works like **. foo(1,[2,3]) [1,[2,3]] foo(1,{2 => 3}) [1,{2=>3}]
  • 13. Positional Arguments : Combinations sub foo($a,*@b) { say “$a : {@b.perl}”; } foo(1) 1 : [] foo( 1,[2,3] ) 1 : [2,3] ● You can combine positional and slurpy argument. ● The slurpy has to come last. ● You can only have one slurpy argument. foo(1,2,3) 1 : [2,3] foo(1,2,3,{a => 5}) 1:[2,3,:a(5)]
  • 14. Named Arguments sub foo(:$a,:$b!) { say “$a & $b”; } foo(a=>”b”,b=>”c”) b & c foo(:a<bar>) Required named parameter 'b' not passed ● Define named arguments with a ‘:’ in front of the lexical variable. ● Named arguments are not required. ● Append the name with ! to make it required. foo(:b<bar>) & bar Use of uninitialized value $a of type Any in string context.
  • 15. Alternate Named Arguments sub foo(:bar(:$b)) { say $b; } foo(b=>”a”) a foo(:bar<bar>) bar ● Alternate argument names can be nested multiple times : ○ :$val ○ :v($val) ■ :v() in call ○ :v(:$val) ■ :v() or :val() ○ :valid(:v(:$val)) ● All referenced as $val in the sub ● Useful for sub MAIN
  • 16. Combining Named and Positional Arguments sub foo($a,:$b) { say $a if $b; } foo(“Hi”,:b) Hi foo(“Crickets”) ● Positional arguments have to be defined before named. ● You can combine a slurpy positional and named arguments.
  • 17. Named Arguments : Slurpy Hash sub foo(*%a) { say %a; } foo(a=>b) {a => b} Using * on a hash will take all the named argument pairs and put them in the given hash. foo( b => [5,6], :a(b) ) {b => [5,6], a => b} foo( :a, :!b ) { a => True, b => False }
  • 18. Bonus Slide : Types sub num-in-country(:$num, :$ccode){...} sub num-in-country(UInt :$num, Str :$ccode){...} sub num-in-country(UInt :$num, Str :$ccode where * ~~ /^ <[a..z]> ** 2 $/ ){...} subset CCode of Str where * ~~ /^ <[a..z]> ** 2 $/; sub num-in-country(UInt :$num, CCode :$ccode){...} Sub coerced-type( Str() $a ) { say “$a could have been many...” }
  • 19. Bonus Slide : Multi Call subset Seven of Int where * == 7; multi sub foo() { 'No args' } multi sub foo(5) { 'Called with 5' } multi sub foo(Seven $) { 'Called with 7' } multi sub foo( *@a ) { '*@a' } multi sub foo( $a ) { '$a' } multi sub foo( Cool $b ) { 'Cool $b' } multi sub foo( Int $b ) { 'Int $b' } multi sub foo( Int $b where * > 0 ) { 'Int $b where * > 0' }