Quoting constructs: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Updated to v0.4.0.) |
|||
Line 185: | Line 185: | ||
5 |
5 |
||
</lang> |
</lang> |
||
=={{header|Nim}}== |
|||
Nim uses single quote for characters.<br/> |
|||
It uses double quotes for single line strings and triple double quotes for multiline strings.<br> |
|||
The standard module <code>strformat</code> provides interpolation in strings.<br> |
|||
Nim allows to define special strings, for instance to describe regular expressions or PEGs (parsing expression grammar).<br/> |
|||
Arrays literals are defined as a list of values between brackets.<br/> |
|||
Preceding an array literal with an @ creates a sequence literal instead.<br/> |
|||
Tuples literals are defined as a list of values between parentheses. Field names may be specified by preceding a value by the name followed by a colon.<br/> |
|||
<lang Nim> |
|||
echo "A simple string." |
|||
echo "A simple string including tabulation special character \\t: \t." |
|||
echo """ |
|||
First part of a multiple string, |
|||
followed by second part |
|||
and third part. |
|||
""" |
|||
echo r"A raw string containing a \." |
|||
# Interpolation in strings. |
|||
import strformat |
|||
const C = "constant" |
|||
const S = fmt"A string with interpolation of a {C}." |
|||
echo S |
|||
var x = 3 |
|||
echo fmt"A string with interpolation of expression “2 * x + 3”: {2 * x + 3}." |
|||
echo fmt"Displaying “x” with an embedded format: {x:05}." |
|||
# Regular expression string. |
|||
import re |
|||
let r = re"\d+" |
|||
# Pegs string. |
|||
import pegs |
|||
let e = peg"\d+" |
|||
# Array literal. |
|||
echo [1, 2, 3] # Element type if implicit ("int" here). |
|||
echo [byte(1), 2, 3] # Element type is specified by the first element type. |
|||
echo [byte 1, 2, 3] # An equivalent way to specify the type. |
|||
echo @[1, 2, 3] # Sequence of ints. |
|||
# Tuples. |
|||
echo ('a', 1, true) # Tuple without explicit field names. |
|||
echo (x: 1, y: 2) # Tuple with two int fields "x" and "y".</lang> |
|||
{{out}} |
|||
<pre>A simple string. |
|||
A simple string including tabulation special character \t: . |
|||
First part of a multiple string, |
|||
followed by second part |
|||
and third part. |
|||
A raw string containing a \. |
|||
A string with interpolation of a constant. |
|||
A string with interpolation of expression “2 * x + 3”: 9. |
|||
Displaying “x” with an embedded format: 00003. |
|||
[1, 2, 3] |
|||
[1, 2, 3] |
|||
[1, 2, 3] |
|||
@[1, 2, 3] |
|||
('a', 1, true) |
|||
(x: 1, y: 2)</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |