# Span starting from the end

I could not find something similar.

Given, e.g.

lst = Range[10]
(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} *)


the following gives the reverse of lst (I know about Reverse).

lst[[-1 ;; 1 ;; -1]]
(* {10, 9, 8, 7, 6, 5, 4, 3, 2, 1} *)


Why the following does not return the same output?

lst[[;; ;; -1]]


Thanks.

• @Kuba. This means that I have to provide the starting point to Span, right? Otherwise it starts by default from the beginning. Is there any similar concept to Mathematica with Python's slicing? (Thanks for the commenf by the way!) Apr 9, 2017 at 22:01
• What is the difference between Mathematica's Span and Part compared to Python's slicing? So far you have only shown that Mathematica uses a slightly different syntax. Apr 9, 2017 at 22:32
• @C.E. For instance lst[::-1] gives the lst reversed without prividing any start/end value. Apr 9, 2017 at 22:37
• It seems that the syntax sugar for reverse is the only difference between the two. Since Span defaults start position to 1 and end position to All it cannot use ;; ;; -1 to produce the list reversed. See ;; ;; -1 // InputForm. Apr 9, 2017 at 23:38

If you evaluate

;; ;; -1


you get

1 ;; All ;; -1


This shows that the default starting point is always 1, regardless of the step size. Note that ;; is short for Span. Generally, the default for a given argument of Span is independent of the other arguments. The default for the first one (beginning) is always 1, the second one (end) always All and the third one (step size) 1.

;; ;; -1 will not work because if we start at 1, we cannot count downwards without hitting the boundary of the array.

• It is explicitly documented (emphasis is mine): ";;;;k represents a span from the beginning to the end in steps of k." It is the last point before the "Details" section on the Docs page for Span. Apr 10, 2017 at 16:08
• ... but the construct ;; ;; -1 is parsed as a whole, and not as a combination of two Spans. It can be seen from comparing it with ;; ;; ;; -1 and with ( ;; ) (;; -1), and also with ToExpression[";;;;-1", InputForm, HoldComplete]. Tangentially related: (123359). Apr 10, 2017 at 16:21
• @AlexeyPopkov I did not mean to say that it could not be any other way. Apr 10, 2017 at 17:08