diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-09-21 20:22:56 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-09-21 20:22:56 +0200 |
commit | a0edd0af042bd9ea95bae419c2cb54a6d16a6270 (patch) | |
tree | bdef8da8f1abb1e5f28558bfed3d404b932d26cc /modules | |
parent | 88c7715ee5041a3a1e16968c3b73d780e0e87c4f (diff) |
in now a proper goops method
Diffstat (limited to 'modules')
-rw-r--r-- | modules/language/python/compile.scm | 14 | ||||
-rw-r--r-- | modules/language/python/list.scm | 39 |
2 files changed, 45 insertions, 8 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm index eace6ec..2edba8a 100644 --- a/modules/language/python/compile.scm +++ b/modules/language/python/compile.scm @@ -892,13 +892,13 @@ (match op ((or "<" ">" "<=" ">=") (list (G (string->symbol op)) x y)) - ("!=" (list 'not (list 'equal? x y))) - ("==" (list 'equal? x y)) - ("is" (list 'eq? x y)) - ("isnot" (list 'not (list 'eq? x y))) - ("in" (list 'member x y)) - ("notin" (list 'not (list 'member x y))) - ("<>" (list 'not (list 'equal? x y))))) + ("!=" (list (G 'not) (list (G 'equal?) x y))) + ("==" (list (G 'equal?) x y)) + ("is" (list (G 'eq?) x y)) + ("isnot" (list (G 'not) (list (G 'eq?) x y))) + ("in" (list (L 'in) x y)) + ("notin" (list (G 'not) (list (L 'in) x y))) + ("<>" (list (G 'not) (list (G 'equal?) x y))))) (tr op (exp vs x) (exp vs y))))) (define (exp vs x) diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index 3b7fbd5..a88aa0a 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -9,7 +9,7 @@ #:use-module (language python exceptions) #:export (to-list pylist-ref pylist-set! pylist-append! pylist-slice pylist-subset! pylist-reverse! - pylist-pop! pylist-count pylist-extend! + pylist-pop! pylist-count pylist-extend! len in pylist-insert! pylist-remove! pylist-sort!)) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) @@ -557,3 +557,40 @@ (define-method (pylist-index (o <p>) . l) (apply (ref o 'index) l)) +#:len + +(define-method (len (l <pair> )) (length l)) +(define-method (len (v <vector>)) (vector-length v)) +(define-method (len (s <string>)) (string-length s)) +(define-method (len (o <py-list>)) (slot-ref i 'n)) +(define-method (len (o <p>)) ((ref o '__len__))) + +(define-method (in x (l <pair>)) (member x l)) +(define-method (in x (l <vector>)) + (define n (vector-length l)) + (let lp ((i 0)) + (if (< i n) + (if (equal? x (vector-ref l i)) + #t + (lp (+ i 1))) + #f))) + +(define-method (in x (s <string>)) + (let ((n (string-length l)) + (x (if (string? x) (string-ref x 0) x))) + (let lp ((i 0)) + (if (< i n) + (if (equal? x (string-ref s i)) + #t + (lp (+ i 1))) + #f)))) + +(define-method (in x (o <py-list>)) + (define l (slot-ref o 'vec)) + (define n (slot-ref o 'n)) + (let lp ((i 0)) + (if (< i n) + (if (equal? x (vector-ref l i)) + #t + (lp (+ i 1))) + #f))) |