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
)
24 #:replace
(list abs min max
)
25 #:re-export
(Exception StopIteration send sendException next
26 GeneratorExit sendClose RuntimeError
27 len dir next dict None property
)
28 #:export
(print repr complex float int round
29 set all any bin callable
30 chr classmethod staticmethod
31 divmod enumerate filter format
32 getattr hasattr hash hex isinstance
33 iter map sum id input oct ord pow super
))
35 (define-syntax-rule (aif it p x y
) (let ((it p
)) (if it x y
)))
40 ((x) (format #t
"~s~%" x
))
41 (l (format #t
"~s~%" l
))))
43 (define (repr x
) (format #f
"~a" x
))
45 (define string pystring
)
46 (define complex py-complex
)
47 (define float py-float
)
49 (define round py-round
)
54 (define divmod py-divmod
)
55 (define format py-format
)
59 (define-method (callable x
) #f
)
60 (define-method (callable (x <procedure
> )) #t
)
61 (define-method (callable (x <procedure-class
> )) #t
)
62 (define-method (callable (x <applicable
> )) #t
)
63 (define-method (callable (x <primitive-generic
>)) #t
)
64 (define-method (callable (x <p
>))
67 (define chr integer-
>char
)
69 (define classmethod class-method
)
70 (define staticmethod static-method
)
73 (make-generator enumerate
75 (for ((x : l
)) ((i 0))
80 (make-generator enumerate
86 (define miss
((@ (guile) list
) 'miss
))
88 (define* (getattr a b
#:optional
(k miss
))
89 (let ((r (refq a
(symbol->string b
) k
)))
91 (raise AttributeError
"object/class ~a is missing attribute ~a" a b
)
95 (let ((r (refq a
(symbol->string b
) miss
)))
98 (define (isinstance o cl
)
101 (isinstance o
(car cl
))
102 (isinstance o
(cdr cl
)))
107 ((o) (aif it
(wrap-in o
)
109 (aif get
(refq o
'__getitem__
)
115 (raise TypeError
"not iterable" o
))))
131 (with-syntax (((x ...
) (generate-temporaries #'(a ...
))))
132 #'(make-generator map
134 (for ((x : a
) ...
) () (yield (f x ...
))))))))))
136 (define* (sum i
#:optional
(start 0))
137 (for ((x : i
)) ((s start
))
143 (define (id x
) (object-address x
))
151 (def (py-min (* l
) (= key idx
) (= default miss
))
155 (for ((x : it
)) ((s default
) (b default
))
164 (raise ValueError
"min does not work for zero length list")
166 (_ (lp ((@ (guile) list
) l
))))))
168 (def (py-max (* l
) (= key idx
) (= default miss
))
172 (for ((x : it
)) ((s default
) (b default
))
173 (if (eq? default miss
)
181 (raise ValueError
"min does not work for zero length list")
183 (_ (lp ((@ (guile) list
) l
))))))
185 (define (oct x
) (+ "0o" (number->string
(py-index x
) 8)))
186 (define (ord x
) (char->integer
(string-ref (pylist-ref x
0) 0)))
193 (py-mod (expt x y
) z
))))
195 (define-syntax-rule (super . l
) (py-super-mac . l
))