summaryrefslogtreecommitdiff
path: root/modules/language/python
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2017-09-28 23:25:07 +0200
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2017-09-28 23:25:07 +0200
commit710573cbdb4365b02563fd1c01e5f7e78a9ed6de (patch)
treebbe4bffca4a77ddc1b8f88584dd3f393e5dd5899 /modules/language/python
parent269f6dab0b9d3f3d1475a1ff11528b40c1f51af1 (diff)
lists improvements ordering and dir
Diffstat (limited to 'modules/language/python')
-rw-r--r--modules/language/python/compile.scm8
-rw-r--r--modules/language/python/dir.scm42
-rw-r--r--modules/language/python/list.scm2
-rw-r--r--modules/language/python/string.scm8
4 files changed, 38 insertions, 22 deletions
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 <p>))
- (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 <pf>))
- (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 <py-list> )) (pylist-listing))
+(define-method (dir (o <py-list> ))
+ (let ((l1 (pylist-listing)))
+ (if (is-a? o <p>)
+ (let* ((l2 (next-method))
+ (l (+ l1 l2)))
+ (pylist-sort! l)
+ l))))
+
+
(define-method (dir (o <hashtable> )) pyhash-listing)
(define-method (dir (o <py-hashtable>)) pyhash-listing)
(define-method (dir (o <string> )) 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 <string>) (s2 <string>)) (string-ci< s1 s2))
(define-method (<= (s1 <string>) (s2 <string>)) (string-ci<= s1 s2))
(define-method (> (s1 <string>) (s2 <string>)) (string-ci> s1 s2))
(define-method (>= (s1 <string>) (s2 <string>)) (string-ci>= s1 s2))
+(define-method (< (s1 <symbol>) (s2 <symbol>)) (a string-ci< s1 s2))
+(define-method (<= (s1 <symbol>) (s2 <symbol>)) (a string-ci<= s1 s2))
+(define-method (> (s1 <symbol>) (s2 <symbol>)) (a string-ci> s1 s2))
+(define-method (>= (s1 <symbol>) (s2 <symbol>)) (a string-ci>= s1 s2))
+
+
(define-py (py-zfill zfill s width)
(let* ((n (len s))
(w (pk (pylist-slice s 0 n 1))))