diff options
Diffstat (limited to 'modules/language/python/list.scm')
-rw-r--r-- | modules/language/python/list.scm | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index 7f0d7e4..1a3e7c5 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -515,12 +515,16 @@ (define-method (pylist-remove! (o <p>) . l) (apply (ref o 'remove) l)) ;; SORT! -(define-method (pylist-sort! (o <py-list>) ) - (let lp ((l (sort (to-list o) <)) (i 0)) - (if (pair? l) - (begin - (pylist-set! o i (car l)) - (lp (cdr l) (+ i 1)))))) +(define (id x) id) +(define-method (pylist-sort! (o <py-list>) . l) + (apply + (lambda* (#:key (key id) (reverse #f)) + (let lp ((l (sort (map key (to-list o)) (if reverse > <))) (i 0)) + (if (pair? l) + (begin + (pylist-set! o i (car l)) + (lp (cdr l) (+ i 1)))))) + l)) (define-method (pylist-sort! (o <p>) . l) (apply (ref o 'sort) l)) @@ -686,10 +690,13 @@ (define-python-class list (<py-list>) (define __init__ - (lambda (self . x) - (slot-set! self 'vec (make-vector 30)) - (slot-set! self 'n 0) - (for-each (lambda (x) (pylist-append! self x)) x)))) + (case-lambda + ((self) + (slot-set! self 'vec (make-vector 30)) + (slot-set! self 'n 0)) + ((self it) + (__init__ self) + (for ((i : it)) () (pylist-append self i)))))) (define pylist list) |