From 45bbe73fd60be1758d3e574a16278e2119df15f9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Doderlein Date: Wed, 7 Jan 2026 23:27:55 +0100 Subject: [PATCH 1/2] Update proposition for slicing out of bound --- courses/Rascal/Expressions/Values/List/Slice/Slice.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/courses/Rascal/Expressions/Values/List/Slice/Slice.md b/courses/Rascal/Expressions/Values/List/Slice/Slice.md index b3201d556..765c71d18 100644 --- a/courses/Rascal/Expressions/Values/List/Slice/Slice.md +++ b/courses/Rascal/Expressions/Values/List/Slice/Slice.md @@ -47,16 +47,16 @@ The slice parameters `begin`, `end`, and `step` are determined as follows: * _Exp~2~_: ** If _Exp~2~_ is absent, then `begin = 0`. -** Otherwise, if _N~2~_ >= 0 then `begin = N~2~` else `begin = N~2~ + Len`. +** Otherwise, if _N~2~_ >= 0 then `begin = min(N~2~, Len)` else `begin = max(N~2~ + Len, 0)`. * _Exp~4~_: ** If _Exp~4~_ is absent, then `end = Len`. -** Otherwise, if _N~4~_ >= 0, then `end = N~4~` else `end = N~4~ + Len`. +** Otherwise, if _N~4~_ >= 0, then `end = min(N~4~, Len-1)` else `end = max(N~4~ + Len, 0)`. * _Exp~3~_: ** If _Exp~3~_ is absent, then if `begin < end` then `step = 1` else `step = -1`. ** Otherwise, if `begin < end`, then `step = N~3~ - begin` else `step = begin - N~3~`. -Now, the constraints `0 <= begin < Len` and `0 < end < Len` should hold, +Now, the constraints `0 <= begin < Len` and `0 < end <= Len` should hold, otherwise the exception `IndexOutOfBounds` is thrown. The slice consists of the elements `L[begin]`, `L[begin+step]`, `L[end - step]`. @@ -126,6 +126,8 @@ Slices not do go "out of bounds". Instead they just stop at the end or beginning ```rascal-shell,continue L[..10]; L[..-11]; +L[-12..12]; +L[10..-10]; ``` From a6a1012effadac8aab30c4993664c603cbd71a74 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Doderlein Date: Thu, 8 Jan 2026 09:52:32 +0100 Subject: [PATCH 2/2] Fix indices --- courses/Rascal/Expressions/Values/List/Slice/Slice.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/courses/Rascal/Expressions/Values/List/Slice/Slice.md b/courses/Rascal/Expressions/Values/List/Slice/Slice.md index 765c71d18..df62af5d3 100644 --- a/courses/Rascal/Expressions/Values/List/Slice/Slice.md +++ b/courses/Rascal/Expressions/Values/List/Slice/Slice.md @@ -47,16 +47,16 @@ The slice parameters `begin`, `end`, and `step` are determined as follows: * _Exp~2~_: ** If _Exp~2~_ is absent, then `begin = 0`. -** Otherwise, if _N~2~_ >= 0 then `begin = min(N~2~, Len)` else `begin = max(N~2~ + Len, 0)`. +** Otherwise, if _N~2~_ >= 0 then `begin = min(N~2~, Len-1)` else `begin = max(N~2~ + Len, 0)`. * _Exp~4~_: ** If _Exp~4~_ is absent, then `end = Len`. -** Otherwise, if _N~4~_ >= 0, then `end = min(N~4~, Len-1)` else `end = max(N~4~ + Len, 0)`. +** Otherwise, if _N~4~_ >= 0, then `end = min(N~4~, Len)` else `end = max(N~4~ + Len, 0)`. * _Exp~3~_: ** If _Exp~3~_ is absent, then if `begin < end` then `step = 1` else `step = -1`. ** Otherwise, if `begin < end`, then `step = N~3~ - begin` else `step = begin - N~3~`. -Now, the constraints `0 <= begin < Len` and `0 < end <= Len` should hold, +Now, the constraints `0 <= begin < Len` and `0 <= end <= Len` should hold, otherwise the exception `IndexOutOfBounds` is thrown. The slice consists of the elements `L[begin]`, `L[begin+step]`, `L[end - step]`.