Skip to content

Commit f75f602

Browse files
committed
Add rationale for .. notation
1 parent 1e985db commit f75f602

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

active/0000-slice-notation.md

+13
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ Like `Index`, uses of this notation will auto-deref just as if they were method
8585
invocations. So if `T` implements `Slice<uint, [U]>`, and `s: Smaht<T>`, then
8686
`s[]` compiles and has type `&[U]`.
8787

88+
## Rationale for the notation
89+
90+
The choice of square brackets for slicing is straightforward: it matches our
91+
indexing notation, and slicing and indexing are closely related.
92+
93+
Some other languages (like Python and Go -- and Fortran) use `:` rather than
94+
`..` in slice notation. The choice of `..` here is influenced by its use
95+
elsewhere in Rust, for example for fixed-length array types `[T, ..n]`. The `..`
96+
for slicing has precedent in Perl and D.
97+
98+
See [Wikipedia](http://en.wikipedia.org/wiki/Array_slicing) for more on the
99+
history of slice notation in programming languages.
100+
88101
# Drawbacks
89102

90103
The main drawback is the increase in complexity of the language syntax. This

0 commit comments

Comments
 (0)