In Quoting constructs§
See primary documentation in context for Literal strings: Q
Q[A literal string] 「More plainly.」 Q^Almost any non-word character can be a delimiter!^ Q「「Delimiters can be repeated/nested if they are adjacent.」」 Q⦅Quoting with fancy unicode pairs⦆
Delimiters can be nested, but in the plain Q
form, backslash escapes aren't allowed. In other words, basic Q
strings are as literal as possible.
Some delimiters are not allowed immediately after Q
, q
, or qq
. Any characters that are allowed in identifiers are not allowed to be used, since in such a case, the quoting construct together with such characters are interpreted as an identifier. In addition, ( )
is not allowed because that is interpreted as a function call. If you still wish to use those characters as delimiters, separate them from Q
, q
, or qq
with a space. Please note that some natural languages use a left delimiting quote on the right side of a string. Q
will not support those as it relies on unicode properties to tell left and right delimiters apart.
Q'this will not work!' Q(this won't work either!)
The examples above will produce an error. However, this will work
Q (this is fine, because of space after Q) Q 'and so is this' Q<Make sure you <match> opening and closing delimiters> Q{This is still a closing curly brace → \}
These examples produce:
this is fine, because of space after Q and so is this Make sure you <match> opening and closing delimiters This is still a closing curly brace → \
The behavior of quoting constructs can be modified with adverbs, as explained in detail in later sections.
Short | Long | Meaning |
:x | :exec | Execute as command and return results |
:w | :words | Split result on words (no quote protection) |
:ww | :quotewords | Split result on words (with quote protection) |
:q | :single | Interpolate \\, \qq[...] and escaping the delimiter with \ |
:double | Interpolate with :s, :a, :h, :f, :c, :b | |
:s | :scalar | Interpolate $ vars |
:a | :array | Interpolate @ vars (when followed by postcircumfix) |
:h | :hash | Interpolate % vars (when followed by postcircumfix) |
:f | :function | Interpolate & calls |
:c | :closure | Interpolate {...} expressions |
:b | :backslash | Enable backslash escapes (\n, \qq, \$foo, etc) |
:to | :heredoc | Parse result as heredoc terminator |
:v | :val | Convert to allomorph if possible |
These adverbs can be used together with Q
, so that it will interpolate even if the quoting operator does not:
my %þ = :is-mighty; say Q "Þor %þ<>"; # OUTPUT: «Þor %þ<>» say Q:h"Þor %þ<>"; # OUTPUT: «Þor is-mighty True» %þ = :42foo, :33bar; say Q:h:c "Þor %þ<> → { [+] %þ.values}"; # OUTPUT: «Þor bar 33foo 42 → 75» my @þ= <33 44>; say Q:a "Array contains @þ[]"; # OUTPUT: «Array contains 33 44» say Q:v<33> + 3; # OUTPUT: «36»
By default, and as shown, Q
quotes directly without any kind of transformation of the quoted string. The adverbs will modify its behavior, converting, for instance, the string into an allomorph (with the :v
adverb) or allowing interpolation of hashes (via :h
) or {}
code sections (via :c
). Arrays and hashes must be followed by a postcircumfix; that is, the sigiled identifier will not interpolate, but followed by an indexing, decont operator or a method call with parentheses, it will:
my @þ= <33 44>; say Q:a "Array contains @þ.elems()"; # OUTPUT: «Array contains 2»
The same code without the parentheses will simply not interpolate, absent the post-circumfix operator.