Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Raku (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Parameter passing modes==== Raku provides three basic modes of parameter passing: positional parameters, [[named parameter]]s, and slurpy parameters. 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. Named-only parameters (indicated by a <code>:</code> before the parameter name) can only be passed by specifying its name, i.e. it never captures a positional argument. Slurpy parameters (indicated by an <code>*</code> before the parameter name) are Raku's tool for creating [[variadic function]]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: <syntaxhighlight lang="raku"> 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) </syntaxhighlight> Positional parameters, such as those used above, are always required unless followed by <code>?</code> to indicate that they are optional. Named parameters are optional by default, but may be marked as required by adding <code>!</code> after the variable name. Slurpy parameters are ''always'' optional.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)