diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-09-28 22:46:02 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-09-28 22:46:02 +0200 |
commit | 269f6dab0b9d3f3d1475a1ff11528b40c1f51af1 (patch) | |
tree | e6dfca2302bf1f94c5d8bb563975d699e2d98267 /modules/language/python/list.scm | |
parent | 4deff738d3727dbe71a66f6f052822ea7cb10963 (diff) |
improved fastmap and dir function
Diffstat (limited to 'modules/language/python/list.scm')
-rw-r--r-- | modules/language/python/list.scm | 103 |
1 files changed, 99 insertions, 4 deletions
diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index f74e2b1..532868b 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -13,7 +13,10 @@ pylist-slice pylist-subset! pylist-reverse! pylist-pop! pylist-count pylist-extend! len in pylist-insert! pylist-remove! pylist-sort! - pylist-index pylist-null pylist-delete!)) + pylist-index pylist-null pylist-delete! + pylist pylist-listing)) + +(define scm-list list) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) @@ -162,8 +165,9 @@ (define-method (pylist-slice (o <string>) n1 n2 n3) (list->string - (to-list - (pylist-slice (to-pylist o) n1 n2 n3)))) + (map (lambda (x) (string-ref x 0)) + (to-list + (pylist-slice (to-pylist o) n1 n2 n3))))) (define-method (pylist-slice (o <pair>) n1 n2 n3) (to-list @@ -462,7 +466,7 @@ (if (< i (string-length str)) (let ((ret (string-ref str i))) (slot-set! o 'i (+ i 1)) - (list->string (list ret))) + (list->string (scm-list ret))) (throw StopIteration)))) (define-method (next (o <py-list-iter>)) @@ -633,3 +637,94 @@ (define-method (in x (o <p>)) ((ref o '__contains__) x)) + +(define-syntax-rule (defgen (op o1 o2) code ...) + (begin + (define-method (op (o1 <py-list>) (o2 <py-list>)) code ...) + (define-method (op (o1 <pair>) (o2 <pair> )) code ...) + (define-method (op (o1 <vector>) (o2 <vector>)) code ...))) + +(defgen (< o1 o2) + (let ((n1 (len o1)) + (n2 (len o2))) + (for ((x1 : o1) (x2 : o2)) () + (if (< x1 x2) + (break #t)) + #:final + (< n1 n2)))) + +(defgen (<= o1 o2) + (let ((n1 (len o1)) + (n2 (len o2))) + (for ((x1 : o1) (x2 : o2)) () + (if (< x1 x2) + (break #t)) + #:final + (<= n1 n2)))) + +(defgen (> o1 o2) + (let ((n1 (len o1)) + (n2 (len o2))) + (for ((x1 : o1) (x2 : o2)) () + (if (> x1 x2) + (break #t)) + #:final + (> n1 n2)))) + +(defgen (>= o1 o2) + (let ((n1 (len o1)) + (n2 (len o2))) + (for ((x1 : o1) (x2 : o2)) () + (if (> x1 x2) + (break #t)) + #:final + (>= n1 n2)))) + +(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)))) + +(define pylist list) + + +(define (pylist-listing) + (let ((l + (to-pylist + (map symbol->string + '(append + count + extend + index + pop + insert + remove + reverse + sort + __init__ + __le__ + __lt__ + __gt__ + __ge__ + __ne__ + __eq__ + __len__ + __init__ + __add__ + __mul__ + __rmul__ + __radd__ + __repr__ + __containes__ + __getattr__ + __setattr__ + __delattr__ + __delitem__ + __setitem__ + __iter__ + ))))) + + (pylist-sort! l) + l)) |