diff options
Diffstat (limited to 'modules/language/python/dict.scm')
-rw-r--r-- | modules/language/python/dict.scm | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/modules/language/python/dict.scm b/modules/language/python/dict.scm index 5b6567b..f4d13a5 100644 --- a/modules/language/python/dict.scm +++ b/modules/language/python/dict.scm @@ -17,6 +17,8 @@ py-hash-ref dict pyhash-listing )) +(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) + (define (h x n) (modulo (py-hash x) n)) (define (py-hash-ref . l) @@ -155,15 +157,19 @@ (define-method (nm (o class) l ...) code ...) ... (define-method (nm (o <p>) l ...) - ((ref o 'n) l ...)))) + (aif it (ref o 'n) + (it l ...) + (next-method))))) ((_ (nm n o l ... . u) (class code ...) ...) (begin (define-method (nm (o class) l ... . u) code ...) ... (define-method (nm (o <p>) l ... . u) - (apply (ref o 'n) l ... u)))))) - - + (aif it (ref o 'n) + (apply it l ... u) + (next-method))))))) + + (define-py (py-copy copy o) (<hashtable> @@ -475,19 +481,21 @@ (define-python-class dict (<py-hashtable>) (define __init__ - (case-lambda - ((self) - (let ((r (make-py-hashtable))) - (slot-set! self 't (slot-ref r 't)) - (slot-set! self 'h (slot-ref r 'h)) - (slot-set! self 'n (slot-ref r 'n)))) - ((self x) - (__init__ self) - (if (is-a? x <py-hashtable>) - (hash-for-each - (lambda (k v) - (pylist-set! self k v)) - (slot-ref x 't))))))) + (letrec ((__init__ + (case-lambda + ((self) + (let ((r (make-py-hashtable))) + (slot-set! self 't (slot-ref r 't)) + (slot-set! self 'h (slot-ref r 'h)) + (slot-set! self 'n (slot-ref r 'n)))) + ((self x) + (__init__ self) + (if (is-a? x <py-hashtable>) + (hash-for-each + (lambda (k v) + (pylist-set! self k v)) + (slot-ref x 't))))))) + __init__))) (define (pyhash-listing) (let ((l (to-pylist |