Skip to content

Commit 9e59d76

Browse files
authored
Specify the convenience method for list multiple assignment
Fixes #509.
1 parent 283e1b6 commit 9e59d76

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

infra.bs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,37 @@ out-of-bounds, except when used with <a for=list>exists</a>.
14261426
"<code>b</code>", "<code>c</code>", "<code>a</code>" ». Then |example|[1] is the <a>string</a>
14271427
"<code>b</code>".
14281428

1429+
<p>For notational convenience, a multiple assignment syntax may be used to assign multiple variables
1430+
to the <a>list</a>'s <a for=list>items</a>, by surrounding the variables to be assigned by « »
1431+
characters and separating each variable name with a comma. The <a>list</a>'s <a for=list>size</a>
1432+
must be the same as the number of variables to be assigned. Each variable given is then set to the
1433+
value of the <a>list</a>'s <a for=list>item</a> at the corresponding index.
1434+
1435+
<div class=example id=example-list-multiple-assignment>
1436+
<ol>
1437+
<li><p>Let |value| be the <a>list</a> « "<code>a</code>", "<code>b</code>", "<code>c</code>" ».
1438+
1439+
<li><p>Let « |a|, |b|, |c| » be |value|.
1440+
1441+
<li><p><a>Assert</a>: |a| is "<code>a</code>".
1442+
1443+
<li><p><a>Assert</a>: |b| is "<code>b</code>".
1444+
1445+
<li><p><a>Assert</a>: |c| is "<code>c</code>".
1446+
</ol>
1447+
</div>
1448+
1449+
<p>When a <a>list</a>'s contents are not fully controlled, as is the case for lists from user input,
1450+
the <a>list</a>'s <a for=list>size</a> should be checked to ensure it is the expected size before
1451+
list multiple assignment syntax is used.
1452+
1453+
<div class=example id=example-list-multiple-assignment-size>
1454+
<ol>
1455+
<li><p>If |list|'s <a for=list>size</a> is not <code>3</code>, then return failure.
1456+
<li><p>Let « |a|, |b|, |c| » be |list|.
1457+
</ol>
1458+
</div>
1459+
14291460
<hr>
14301461

14311462
<p>To <dfn export for=list>append</dfn> to a <a>list</a> that is not an <a>ordered set</a> is to

0 commit comments

Comments
 (0)