(define-module (language python dir) #:use-module (language python list) #:use-module (language python for) #:use-module (language python dict) #:use-module (language python string) #:use-module (language python bytes) #:use-module (language python number) #:use-module (language python bytes) #:use-module (oop goops) #:use-module (ice-9 vlist) #:use-module (oop pf-objects) #:export (dir)) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) (define-method (dir) (pylist)) (define (chash-for-each f c) (let ((h (slot-ref c 'h))) (if (is-a? c ) (let ((hh (make-hash-table))) (vhash-fold (lambda (k v s) (when (not (hash-ref hh k)) (hash-set! hh k #t) (f k v)) s) #f h)) (hash-for-each f h)))) (define (get-from-class c f) (let lp ((pl (ref c '__mro__))) (if (pair? pl) (begin (chash-for-each f (car pl)) (lp (cdr pl)))))) (define-method (dir (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 '()) (f (lambda (k v) (set! l (cons k l))))) (chash-for-each f o) (get-from-class c f) (hash-for-each (lambda (k v) (pylist-append! l k)) h) (to-pylist (map symbol->string (sort l <)))))) (let* ((h (make-hash-table)) (c o) (l '()) (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 )) (let ((l1 (pk (pylist-listing)))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pyhash-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pystring-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pyint-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pyfloat-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pycomplex-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pybytes-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (let ((l1 (pybytesarray-listing))) (if (is-a? o

) (let* ((l2 (next-method)) (l (+ l1 l2))) (pylist-sort! l) l) l1))) (define-method (dir (o )) (pyhash-listing)) (define-method (dir (o )) (pystring-listing)) (define-method (dir (o )) (pycomplex-listing)) (define-method (dir (o )) (pyfloat-listing)) (define-method (dir (o )) (pyint-listing)) (define-method (dir (o )) (pybytes-listing)) (define-method (dir) (let ((l '())) (module-for-each (lambda (m . u) (set! l (cons (symbol->string m) l))) (current-module)) (let ((ret (to-pylist l))) (pylist-sort! ret) ret))) (define-method (dir (o )) (let ((ret (to-pylist (map (lambda (x) (let ((x (car x))) (if (symbol? x) (symbol->string x) x))) (procedure-properties o))))) (pylist-sort! ret) ret))