In Glossary§
See primary documentation in context for Colon pair and colon list
A colon pair is a shorthand syntax used to create or visually present a Pair
object. The two most common forms are:
:a(4) # Same as "a" => 4, same as Pair.new("a", 4) :a<4> # Same as "a" => "4", same as Pair.new("a", val("4"))
This is also known as the adverbial pair form.
Note: when the part after the colon and before the balanced delimiters is not a legal identifier, other semantics apply, not all of which produce Pair
objects.
Two other common forms are:
:a # Same as :a(True) :!a # Same as :a(False)
A colon list just means that a list that contains only colon pairs, does not need commas, or even spaces:
:a(4):c:!d:c # Same as a => 4, c => True, d => False, c => True
Finally, if there is a variable with the same name as an intended adverbial pair, you don't have to specify the name twice, but just specify the adverb with the appropriate sigil:
variable only | same as |
---|---|
:$foo | foo => $foo |
:@bar | bar => @bar |
:%mapper | mapper => %mapper |
:&test | test => &test |
See also Adverb.