Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify the convenience method for List multiple assignment #638

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,37 @@ out-of-bounds, except when used with <a for=list>exists</a>.
"<code>b</code>", "<code>c</code>", "<code>a</code>" ». Then |example|[1] is the <a>string</a>
"<code>b</code>".

<p>For notational convenience, a multiple assignment syntax may be used to assign multiple variables
to the <a>list</a>'s <a for=list>items</a>, by surrounding the variables to be assigned by « »
characters and separating each variable name with a comma. The <a>list</a>'s <a for=list>size</a>
must be the same as the number of variables to be assigned. Each variable given is then set to the
value of the <a>list</a>'s <a for=list>item</a> at the corresponding index.

<div class=example id=example-list-multiple-assignment>
<ol>
<li><p>Let |value| be the <a>list</a> « "<code>a</code>", "<code>b</code>", "<code>c</code>" ».

<li><p>Let « |a|, |b|, |c| » be |value|.

<li><p><a>Assert</a>: |a| is "<code>a</code>".

<li><p><a>Assert</a>: |b| is "<code>b</code>".

<li><p><a>Assert</a>: |c| is "<code>c</code>".
</ol>
</div>

<p>When a <a>list</a>'s contents are not fully controlled, as is the case for lists from user input,
the <a>list</a>'s <a for=list>size</a> should be checked to ensure it is the expected size before
list multiple assignment syntax is used.

<div class=example id=example-list-multiple-assignment-size>
<ol>
<li><p>If |list|'s <a for=list>size</a> is not <code>3</code>, then return failure.
<li><p>Let « |a|, |b|, |c| » be |list|.
</ol>
</div>
annevk marked this conversation as resolved.
Show resolved Hide resolved

<hr>

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