D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22580 - [Arrays]
Summary: [Arrays]
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL: http://dlang.org/
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-09 14:14 UTC by Kurt Krueckeberg
Modified: 2024-12-15 15:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kurt Krueckeberg 2021-12-09 14:14:25 UTC
I am new to D, but the code example explanation in section 12.6 is confusing. The code example in section 12.6 refers to the "slice operator":

"When the slice operator appears as the left-hand side of an assignment expression, it means that the contents of the array are the target of the assignment rather than a reference to the array..."

Is there really a special "slice operator"? The operator used in the example in section 12.6 is array index operator, [].  So shouldn't the explanation be changed to refer to the index operator (being applied to a slice that appears on the left-hand side of an assignment statement)? To me, it is clearer to say something like:

"When the slice appears on the left-hand side of an assignment with the index operator, it means that the contents of the array are the target of the assignment rather than a reference to the array..."

Or to say:

"When the slice is indexed with the [] operator and it appears on the left-hand side of an assignment, it means that the contents of the array are the target of the assignment rather than a reference to the array..."

Or simply:

"When the slice is indexed and it appears on the left-hand side of an assignment, it means that the contents of the array are the target of the assignment rather than a reference to the array..."
Comment 1 Andrej Mitrovic 2022-07-06 07:55:39 UTC
(In reply to Kurt Krueckeberg from comment #0)
> I am new to D, but the code example explanation in section 12.6 is
> confusing. The code example in section 12.6 refers to the "slice operator":
> 
> "When the slice operator appears as the left-hand side of an assignment
> expression, it means that the contents of the array are the target of the
> assignment rather than a reference to the array..."
> 
> Is there really a special "slice operator"? The operator used in the example
> in section 12.6 is array index operator, [].  So shouldn't the explanation
> be changed to refer to the index operator (being applied to a slice that
> appears on the left-hand side of an assignment statement)? To me, it is
> clearer to say something like:
> 
> "When the slice appears on the left-hand side of an assignment with the
> index operator, it means that the contents of the array are the target of
> the assignment rather than a reference to the array..."
> 
> Or to say:
> 
> "When the slice is indexed with the [] operator and it appears on the
> left-hand side of an assignment, it means that the contents of the array are
> the target of the assignment rather than a reference to the array..."
> 
> Or simply:
> 
> "When the slice is indexed and it appears on the left-hand side of an
> assignment, it means that the contents of the array are the target of the
> assignment rather than a reference to the array..."

The slice operator is specifically `[]` or `[1..2]`. And you can think of `[]` as being the same as `[0..$]`, where $ is the array length.

The index operator is `[1]` for example. It doesn't return a slice of the original array, it returns a single element from the array. That's indexing, not slicing.

Perhaps there should be better documentation about the difference between the two though.
Comment 2 dlangBugzillaToGithub 2024-12-15 15:27:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dlang.org/issues/4121

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB