diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-10-04 20:03:43 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-10-04 20:03:43 +0200 |
commit | 596eebc8eea930e964114defa57ac39e42c2a605 (patch) | |
tree | a371c6d6b19a23e0a375446a498f59c45a8cebd1 /modules/language/python/list.scm | |
parent | deaef820fdea3fac87c1c8dc3bfb6208d3820621 (diff) |
property values
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) |