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!
===Junctions=== Raku introduces the concept of ''junctions'': values that are composites of other values.<ref name="syn9"/> In their simplest form, junctions are created by combining a set of values with junctive [[Operator (programming)|operator]]s: <syntaxhighlight lang="raku"> # Example for | ("any") Junction: my $color = 'white'; unless $color eq 'white' | 'black' | 'gray' | 'grey' { die "Color printing not supported\n"; } # Example for & ("all") Junction: my $password = 'secret!123'; if $password ~~ /<:alpha>/ & /<:digit>/ & /<:punct>/ { say "Your password is reasonably secure"; } </syntaxhighlight> <code>|</code> indicates a value which is equal to either its left- ''or'' right-hand arguments. <code>&</code> 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, <code>("apple"|"banana") ~ "s"</code> would yield <code>"apples"|"bananas"</code>. In comparisons, junctions return a single true or false result for the comparison. "<code>any</code>" junctions return true if the comparison is true for any one of the elements of the junction. "<code>all</code>" 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]] that is constrained to junctions of types: <syntaxhighlight lang="raku"> subset Color of Any where RGB_Color | CMYK_Color; sub get_tint(Color $color, Num $opacity) { ... } </syntaxhighlight>
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)