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
8 #:use-module
(language python exceptions
)
9 #:use-module
(language python def
)
10 #:use-module
(language python for
)
11 #:use-module
(language python try
)
12 #:use-module
(language python yield
)
13 #:use-module
(language python list
)
14 #:use-module
(language python dict
)
15 #:use-module
(language python set
)
16 #:use-module
(language python compile
)
17 #:use-module
(language python string
)
18 #:use-module
(language python set
)
19 #:use-module
(language python number
)
20 #:use-module
(language python dir
)
21 #:use-module
(language python hash
)
22 #:use-module
(language python property
)
23 #:use-module
(language python range
)
24 #:use-module
(language python tuple
)
26 #:replace
(list abs min max hash
)
27 #:re-export
(Exception StopIteration send sendException next
28 GeneratorExit sendClose RuntimeError
29 len dir next dict None property range
31 #:export
(print repr complex float int round
32 set all any bin callable
33 chr classmethod staticmethod
34 divmod enumerate filter format
35 getattr hasattr hex isinstance
36 iter map sum id input oct ord pow super
))
38 (define-syntax-rule (aif it p x y
) (let ((it p
)) (if it x y
)))
43 ((x) (format #t
"~s~%" x
))
44 (l (format #t
"~s~%" l
))))
46 (define (repr x
) (format #f
"~a" x
))
48 (define string pystring
)
49 (define complex py-complex
)
50 (define float py-float
)
52 (define round py-round
)
57 (define divmod py-divmod
)
58 (define format py-format
)
62 (define-method (callable x
) #f
)
63 (define-method (callable (x <procedure
> )) #t
)
64 (define-method (callable (x <procedure-class
> )) #t
)
65 (define-method (callable (x <applicable
> )) #t
)
66 (define-method (callable (x <primitive-generic
>)) #t
)
67 (define-method (callable (x <p
>))
70 (define chr integer-
>char
)
72 (define classmethod class-method
)
73 (define staticmethod static-method
)
76 (make-generator enumerate
78 (for ((x : l
)) ((i 0))
83 (make-generator enumerate
89 (define miss
((@ (guile) list
) 'miss
))
91 (define* (getattr a b
#:optional
(k miss
))
92 (let ((r (refq a
(symbol->string b
) k
)))
94 (raise AttributeError
"object/class ~a is missing attribute ~a" a b
)
98 (let ((r (refq a
(symbol->string b
) miss
)))
101 (define (isinstance o cl
)
104 (isinstance o
(car cl
))
105 (isinstance o
(cdr cl
)))
110 ((o) (aif it
(wrap-in o
)
112 (aif get
(refq o
'__getitem__
)
118 (raise TypeError
"not iterable" o
))))
134 (with-syntax (((x ...
) (generate-temporaries #'(a ...
))))
135 #'(make-generator map
137 (for ((x : a
) ...
) () (yield (f x ...
))))))))))
139 (define* (sum i
#:optional
(start 0))
140 (for ((x : i
)) ((s start
))
146 (define (id x
) (object-address x
))
154 (def (py-min (* l
) (= key idx
) (= default miss
))
158 (for ((x : it
)) ((s default
) (b default
))
167 (raise ValueError
"min does not work for zero length list")
169 (_ (lp ((@ (guile) list
) l
))))))
171 (def (py-max (* l
) (= key idx
) (= default miss
))
175 (for ((x : it
)) ((s default
) (b default
))
176 (if (eq? default miss
)
184 (raise ValueError
"min does not work for zero length list")
186 (_ (lp ((@ (guile) list
) l
))))))
188 (define (oct x
) (+ "0o" (number->string
(py-index x
) 8)))
189 (define (ord x
) (char->integer
(string-ref (pylist-ref x
0) 0)))
196 (py-mod (expt x y
) z
))))
198 (define-syntax-rule (super . l
) (py-super-mac . l
))