diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2018-08-16 22:41:44 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2018-08-16 22:41:44 +0200 |
commit | 6ae273a9f5a0bbc9c02627287c8b5f958fc2095f (patch) | |
tree | 5c0a05616acb6d9ea70eefcedc33cf65fd83b0d0 /modules/language/python/list.scm | |
parent | 849f5d8389aecbe4c7152061b118f5f6b098b8ba (diff) |
improvements of optparse
Diffstat (limited to 'modules/language/python/list.scm')
-rw-r--r-- | modules/language/python/list.scm | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index 99c4f59..5cdb3d3 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -182,15 +182,14 @@ ;;SLICE -(define-method (pylist-slice (o <p>) n1 n2 n3) +(define-method (pylist-slice (o <p>) . l) (aif it (ref o '__getslice__) - (it n1 n2 n3) + (apply it l) (next-method))) (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)) - (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))) @@ -425,16 +424,23 @@ (next-method))) ;;POP! -(define-method (pylist-pop! (o <py-list>)) - (let* ((n (slot-ref o 'n)) - (m (- n 1)) - (vec (slot-ref o 'vec))) - (if (> n 0) - (let ((ret (vector-ref vec m))) - (slot-set! o 'n m) - (vector-set! vec m #f) - ret) - (raise IndexError "pop from empty list")))) +(define-method (pylist-pop! (o <py-list>) . l) + (let ((index (if (null? l) + #f + (car l)))) + (if index + (let ((x (pylist-ref o index))) + (pylist-delete! o index) + x) + (let* ((n (slot-ref o 'n)) + (m (- n 1)) + (vec (slot-ref o 'vec))) + (if (> n 0) + (let ((ret (vector-ref vec m))) + (slot-set! o 'n m) + (vector-set! vec m #f) + ret) + (raise IndexError "pop from empty list")))))) (define-method (pylist-pop! (o <p>) . l) (aif it (ref o 'pop) |