From 710573cbdb4365b02563fd1c01e5f7e78a9ed6de Mon Sep 17 00:00:00 2001 From: Stefan Israelsson Tampe Date: Thu, 28 Sep 2017 23:25:07 +0200 Subject: lists improvements ordering and dir --- modules/language/python/compile.scm | 8 +++---- modules/language/python/dir.scm | 42 ++++++++++++++++++++++--------------- modules/language/python/list.scm | 2 +- modules/language/python/string.scm | 8 +++++++ 4 files changed, 38 insertions(+), 22 deletions(-) (limited to 'modules/language/python') diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm index 766c718..a338bf9 100644 --- a/modules/language/python/compile.scm +++ b/modules/language/python/compile.scm @@ -703,14 +703,14 @@ ,class ,(map (lambda (x) `(,(O 'get-class) ,x)) parents) #:const + () + #:dynamic ,(match (exp vs defs) (('begin . l) l) ((('begin . l)) l) - (l l)) - #:dynamic - ()))))))) + (l l))))))))) (#:scm ((_ (#:string _ s)) (with-input-from-string s read))) @@ -1634,7 +1634,7 @@ (define-syntax set-x-2 (syntax-rules () ((_ v (#:identifier x) val) - (set v 'x val)) + (set v x val)) ((_ v (#:vecref n) val) (pylist-set! v n val)) ((_ v (#:vecsub x ...) val) diff --git a/modules/language/python/dir.scm b/modules/language/python/dir.scm index ecd85cf..2f23e35 100644 --- a/modules/language/python/dir.scm +++ b/modules/language/python/dir.scm @@ -13,8 +13,8 @@ (define-method (dir) (pylist)) (define (get-from-class c f) - (let lp ((c c)) - (hash-for-each f c) + (let lp ((c c)) + (hash-for-each f (slot-ref c 'h)) (let lpp ((pl (ref c '__parents__))) (if (pair? pl) (begin @@ -23,7 +23,7 @@ (define (get-from-class-f c f) (let lp ((c c)) - (vhash-fold f 0 c) + (vhash-fold f 0 (slot-ref c 'h)) (let lpp ((pl (ref c '__parents__))) (if (pair? pl) (begin @@ -31,49 +31,49 @@ (lpp (cdr pl))))))) (define-method (dir (o

)) - (if (pyclass? o) + (if (not (pyclass? o)) (aif it (ref o '__dir__) (it) (aif it (ref o '__dict__) (let ((l (pylist))) (for ((k v : it)) () (pylist-append! l k)) + (pylist-sort! l) l) (let* ((h (make-hash-table)) (c (ref o '__class__)) - (l (pylist)) - (f (lambda (k v) (pylist-append! h k #t)))) - (hash-for-each f o) + (l '()) + (f (lambda (k v) (set! l (cons k l))))) + (hash-for-each f (slot-ref o 'h)) (get-from-class c f) (hash-for-each (lambda (k v) (pylist-append! l k)) h) - (pylist-sort! l) - l))) + (to-pylist (map symbol->string (sort l <)))))) (let* ((h (make-hash-table)) (c o) (l '()) - (f (lambda (k v) (pylist-append! h k #t)))) + (f (lambda (k v) (hash-set! h k #t)))) (get-from-class c f) (hash-for-each (lambda (k v) (set! l (cons k l))) h) (to-pylist (map symbol->string (sort l <)))))) (define-method (dir (o )) - (if (pyclass? o) + (if (not (pyclass? o)) (aif it (ref o '__dir__) (it) (aif it (ref o '__dict__) (let ((l (pylist))) (for ((k v : it)) () (pylist-append! l k)) + (pylist-sort! l) l) (let* ((h (make-hash-table)) (c (ref o '__class__)) - (l (pylist)) - (f (lambda (k v s) (pylist-append! h k #t)))) - (vhash-fold f 0 o) + (l '()) + (f (lambda (k v s) (set! l (cons k l))))) + (vhash-fold f 0 (slot-ref o 'h)) (get-from-class-f c f) (hash-for-each (lambda (k v) (pylist-append! l k)) h) - (pylist-sort! l) - l))) + (to-pylist (map symbol->string (sort l <)))))) (let* ((h (make-hash-table)) (c o) (l '()) @@ -82,7 +82,15 @@ (hash-for-each (lambda (k v) (set! l (cons k l))) h) (to-pylist (map symbol->string (sort l <)))))) -(define-method (dir (o )) (pylist-listing)) +(define-method (dir (o )) + (let ((l1 (pylist-listing))) + (if (is-a? o

) + (let* ((l2 (next-method)) + (l (+ l1 l2))) + (pylist-sort! l) + l)))) + + (define-method (dir (o )) pyhash-listing) (define-method (dir (o )) pyhash-listing) (define-method (dir (o )) string-listing) diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index 532868b..779ed73 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -717,7 +717,7 @@ __rmul__ __radd__ __repr__ - __containes__ + __contains__ __getattr__ __setattr__ __delattr__ diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm index 8eb84aa..27dd8b8 100644 --- a/modules/language/python/string.scm +++ b/modules/language/python/string.scm @@ -442,11 +442,19 @@ w (pylist-slice w 0 k 1)))))) +(define-syntax-rule (a b x y) (b (symbol->string x) (symbol->string y))) + (define-method (< (s1 ) (s2 )) (string-ci< s1 s2)) (define-method (<= (s1 ) (s2 )) (string-ci<= s1 s2)) (define-method (> (s1 ) (s2 )) (string-ci> s1 s2)) (define-method (>= (s1 ) (s2 )) (string-ci>= s1 s2)) +(define-method (< (s1 ) (s2 )) (a string-ci< s1 s2)) +(define-method (<= (s1 ) (s2 )) (a string-ci<= s1 s2)) +(define-method (> (s1 ) (s2 )) (a string-ci> s1 s2)) +(define-method (>= (s1 ) (s2 )) (a string-ci>= s1 s2)) + + (define-py (py-zfill zfill s width) (let* ((n (len s)) (w (pk (pylist-slice s 0 n 1)))) -- cgit v1.2.3