In Operators§
See primary documentation in context for term { }
If the content is empty, or contains a single list that starts with a Pair
literal or %
-sigiled variable, and the $_
variable or placeholder parameters are not used, the constructor returns a Hash
. Otherwise it constructs a Block
.
To force construction of a Block
, follow the opening brace with a semicolon. To always ensure you end up with a Hash
, you can use %( )
coercer or hash routine instead:
.^name.say; # OUTPUT: «Hash».^name.say; # OUTPUT: «Block».^name.say; # OUTPUT: «Block»%(:).^name.say; # OUTPUT: «Hash»hash(:).^name.say; # OUTPUT: «Hash»
In Operators§
See primary documentation in context for postcircumfix { }
sub postcircumfix:<>(, **,:, :, :, :, :, :)
Universal interface for associative access to zero or more elements of a %container, a.k.a. "hash indexing operator".
my = kiwi => "green", banana => "yellow", cherry => "red";say ; # OUTPUT: «yellow»say .raku; # OUTPUT: «("red", "green")»say :exists; # OUTPUT: «False»= "yellowish", "green";:delete; # note that value is always returned but removal only happens when delete is true.say ; # OUTPUT: «banana => yellowish, kiwi => green, lime => green»
See postcircumfix < >
and postcircumfix « »
for convenient shortcuts, and Subscripts for a more detailed explanation of this operator's behavior and how to implement support for it in custom types.