1 (define-module (language python module python
)
2 #:use-module
(oop goops
)
3 #:use-module
(ice-9 match
)
4 #:use-module
(ice-9 readline
)
5 #:use-module
((oop pf-objects
) #:select
6 (<p
> <property
> class-method static-method refq
))
7 #:use-module
(language python exceptions
)
8 #:use-module
(language python def
)
9 #:use-module
(language python for
)
10 #:use-module
(language python try
)
11 #:use-module
(language python yield
)
12 #:use-module
(language python list
)
13 #:use-module
(language python dict
)
14 #:use-module
(language python set
)
15 #:use-module
(language python compile
)
16 #:use-module
(language python string
)
17 #:use-module
(language python set
)
18 #:use-module
(language python number
)
19 #:use-module
(language python dir
)
20 #:use-module
(language python hash
)
21 #:use-module
(language python property
)
23 #:replace
(list abs min max
)
24 #:re-export
(Exception StopIteration send sendException next
25 GeneratorExit sendClose RuntimeError
26 len dir next dict None property
)
27 #:export
(print repr complex float int round
28 set all any bin callable
29 chr classmethod staticmethod
30 divmod enumerate filter format
31 getattr hasattr hash hex isinstance
32 iter map sum id input oct ord pow
))
34 (define-syntax-rule (aif it p x y
) (let ((it p
)) (if it x y
)))
39 ((x) (format #t
"~s~%" x
))
40 (l (format #t
"~s~%" l
))))
42 (define (repr x
) (format #f
"~a" x
))
44 (define string pystring
)
45 (define complex py-complex
)
46 (define float py-float
)
48 (define round py-round
)
53 (define divmod py-divmod
)
54 (define format py-format
)
58 (define-method (callable x
) #f
)
59 (define-method (callable (x <procedure
> )) #t
)
60 (define-method (callable (x <procedure-class
> )) #t
)
61 (define-method (callable (x <applicable
> )) #t
)
62 (define-method (callable (x <primitive-generic
>)) #t
)
63 (define-method (callable (x <p
>))
66 (define chr integer-
>char
)
68 (define classmethod class-method
)
69 (define staticmethod static-method
)
72 (make-generator enumerate
74 (for ((x : l
)) ((i 0))
79 (make-generator enumerate
85 (define miss
((@ (guile) list
) 'miss
))
87 (define* (getattr a b
#:optional
(k miss
))
88 (let ((r (refq a
(symbol->string b
) k
)))
90 (raise AttributeError
"object/class ~a is missing attribute ~a" a b
)
94 (let ((r (refq a
(symbol->string b
) miss
)))
97 (define (isinstance o cl
)
100 (isinstance o
(car cl
))
101 (isinstance o
(cdr cl
)))
106 ((o) (aif it
(wrap-in o
)
108 (aif get
(refq o
'__getitem__
)
114 (raise TypeError
"not iterable" o
))))
130 (with-syntax (((x ...
) (generate-temporaries #'(a ...
))))
131 #'(make-generator map
133 (for ((x : a
) ...
) () (yield (f x ...
))))))))))
135 (define* (sum i
#:optional
(start 0))
136 (for ((x : i
)) ((s start
))
142 (define (id x
) (object-address x
))
150 (def (py-min (* l
) (= key idx
) (= default miss
))
154 (for ((x : it
)) ((s default
) (b default
))
163 (raise ValueError
"min does not work for zero length list")
165 (_ (lp ((@ (guile) list
) l
))))))
167 (def (py-max (* l
) (= key idx
) (= default miss
))
171 (for ((x : it
)) ((s default
) (b default
))
172 (if (eq? default miss
)
180 (raise ValueError
"min does not work for zero length list")
182 (_ (lp ((@ (guile) list
) l
))))))
184 (define (oct x
) (+ "0o" (number->string
(py-index x
) 8)))
185 (define (ord x
) (char->integer
(string-ref (pylist-ref x
0) 0)))
192 (py-mod (expt x y
) z
))))