diff options
Diffstat (limited to 'modules/language/python/list.scm')
-rw-r--r-- | modules/language/python/list.scm | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index 5cdb3d3..7deda10 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -189,7 +189,13 @@ (define-method (pylist-slice (o <py-list>) n1 n2 n3) (define N (slot-ref o 'n)) - (define (f n) (if (< n 0) (+ N n) n)) + (define (f n) + (let ((x (if (< n 0) (+ N n) n))) + (if (< x 0) + 0 + (if (> x N) + N + x)))) (let* ((n1 (f (if (eq? n1 None) 0 n1))) (n2 (f (if (eq? n2 None) (slot-ref o 'n) n2))) (n3 (f (if (eq? n3 None) 1 n3))) @@ -203,7 +209,13 @@ (define-method (pylist-slice (o <string>) n1 n2 n3) (define N (string-length o)) - (define (f n) (if (< n 0) (+ N n) n)) + (define (f n) + (let ((x (if (< n 0) (+ N n) n))) + (if (< x 0) + 0 + (if (> x N) + N + x)))) (let* ((n1 (f (if (eq? n1 None) 0 n1))) (n2 (f (if (eq? n2 None) (string-length o) n2))) |