5b4daf0f162eb13b45817a7122ac44b2b5939e6c
[software/python-on-guile.git] / modules / language / python / list.scm
1 (define-module (language python list)
2 #:use-module (ice-9 match)
3 #:use-module (oop pf-objects)
4 #:use-module (oop goops)
5 #:use-module (language python hash)
6 #:use-module (language python exceptions)
7 #:use-module (language python yield)
8 #:use-module (language python for)
9 #:use-module (language python try)
10 #:use-module (language python exceptions)
11 #:export (to-list to-pylist <py-list>
12 pylist-ref pylist-set! pylist-append!
13 pylist-slice pylist-subset! pylist-reverse!
14 pylist-pop! pylist-count pylist-extend! len in
15 pylist-insert! pylist-remove! pylist-sort!
16 pylist-index pylist-null pylist-delete!
17 pylist pylist-listing
18 py-all py-any))
19
20 (define scm-list list)
21
22 (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
23
24 (define-class <py-list> () vec n)
25
26 (define-method (pylist-delete! (o <py-list>) k)
27 (let* ((n (slot-ref o 'n))
28 (k (if (< k 0) (+ k n) k)))
29 (pylist-subset! o k (+ k 1) None pylist-null)))
30
31 (define-method (pylist-delete! (o <p>) k)
32 (aif it (ref o '__delitem__)
33 (it k)
34 (next-method)))
35
36 (define pylist-null
37 (let ((o (make <py-list>)))
38 (slot-set! o 'vec (make-vector 0))
39 (slot-set! o 'n 0)
40 o))
41
42
43 (define-method (py-hash (o <py-list>))
44 (let ((n (min complexity (slot-ref o 'n)))
45 (v (slot-ref o 'vec)))
46 (let lp ((i 0) (s 0))
47 (if (< i n)
48 (lp (+ i 1)
49 (xy (py-hash (vector-ref v i)) s))
50 s))))
51
52 (define-method (to-list x)
53 (if (vector? x)
54 (vector->list x)
55 x))
56
57 (define-method (to-list (x <p>))
58 (aif it (ref x '__tolist__)
59 (it)
60 (next-method)))
61
62
63 (define-method (to-list (x <pair>))
64 x)
65
66 (define-method (to-list (x <yield>))
67 (define l '())
68 (catch StopIteration
69 (lambda ()
70 (let lp ()
71 (set! l (cons (next x) l))
72 (lp)))
73 (lambda x
74 (reverse l))))
75
76 (define-method (to-list (x <py-list>))
77 (let ((vec (slot-ref x 'vec))
78 (n (slot-ref x 'n)))
79 (let lp ((i 0))
80 (if (< i n)
81 (cons (vector-ref vec i) (lp (+ i 1)))
82 '()))))
83
84 (define-method (to-pylist (l <py-list>))
85 l)
86
87 (define-method (to-pylist (l <pair>))
88 (let* ((n (length l))
89 (vec (make-vector (* 2 n)))
90 (o (make <py-list>)))
91
92 (let lp ((l l) (i 0))
93 (if (pair? l)
94 (begin
95 (vector-set! vec i (car l))
96 (lp (cdr l) (+ i 1)))))
97
98 (slot-set! o 'n n)
99 (slot-set! o 'vec vec)
100 o))
101
102 (define-method (to-pylist (l <vector>))
103 (to-pylist (vector->list l)))
104
105 (define-method (to-pylist (o <string>))
106 (to-pylist (string->list o)))
107
108 (define-method (to-pylist l)
109 (if (null? l)
110 (let ((o (make <py-list>)))
111 (slot-set! o 'vec (make-vector 4))
112 (slot-set! o 'n 0)
113 o)
114 (error "not able to make a pylist")))
115
116 ;;; REF
117 (define-method (pylist-ref (o <py-list>) nin)
118 (define N (slot-ref o 'n))
119 (define n (if (< nin 0) (+ N nin) nin))
120 (if (and (>= n 0) (< n (slot-ref o 'n)))
121 (vector-ref (slot-ref o 'vec) n)
122 (raise IndexError)))
123
124 (define-method (pylist-ref (o <pair>) n)
125 (define n (if (< n 0) (+ (length o) n)))
126 (list-ref o n))
127
128 (define-method (pylist-ref (o <vector>) n)
129 (vector-ref o n))
130
131 (define-method (pylist-ref (o <p>) n)
132 (aif it (ref o '__getitem__)
133 (it n)
134 (next-method)))
135
136 ;;; SET
137 (define-method (pylist-set! (o <py-list>) nin val)
138 (define N (slot-ref o 'n))
139 (define n (if (< nin 0) (+ N nin) nin))
140
141 (if (and (>= n 0) (< n (slot-ref o 'n)))
142 (vector-set! (slot-ref o 'vec) n val)
143 (raise IndexError)))
144
145 (define-method (pylist-set! (o <pair>) n val)
146 (list-set! o n val))
147
148 (define-method (pylist-set! (o <vector>) n val)
149 (vector-set! o n val))
150
151 (define-method (pylist-set! (o <p>) n val)
152 (aif it (ref o '__setitem__)
153 (it n val)
154 (next-method)))
155
156 ;;SLICE
157 (define-method (pylist-slice (o <p>) n1 n2 n3)
158 (aif it (ref o '__getslice__)
159 (it n1 n2 n3)
160 (next-method)))
161
162 (define-method (pylist-slice (o <py-list>) n1 n2 n3)
163 (define N (slot-ref o 'n))
164 (define (f n) (if (< n 0) (+ N n) n))
165
166 (let* ((n1 (f (if (eq? n1 None) 0 n1)))
167 (n2 (f (if (eq? n2 None) (slot-ref o 'n) n2)))
168 (n3 (f (if (eq? n3 None) 1 n3)))
169
170 (vec (slot-ref o 'vec))
171 (l (let lp ((i n1))
172 (if (< i n2)
173 (cons (vector-ref vec i) (lp (+ i n3)))
174 '()))))
175 (to-pylist l)))
176
177 (define-method (pylist-slice (o <string>) n1 n2 n3)
178 (list->string
179 (map (lambda (x) (string-ref x 0))
180 (to-list
181 (pylist-slice (to-pylist o) n1 n2 n3)))))
182
183 (define-method (pylist-slice (o <pair>) n1 n2 n3)
184 (to-list
185 (pylist-slice (to-pylist o) n1 n2 n3)))
186
187 (define-method (pylist-slice (o <vector>) n1 n2 n3)
188 (list->vector
189 (to-list
190 (pylist-slice (to-pylist o) n1 n2 n3))))
191
192 ;;SUBSET
193 (define-method (pylist-subset! (o <p>) n1 n2 n3 val)
194 (aif it (ref o '__setslice__)
195 (it n1 n2 n3 val)
196 (next-method)))
197
198 (define-method (pylist-subset! (o <py-list>) n1 n2 n3 val)
199 (define N (slot-ref o 'n))
200 (define (f n) (if (< n 0) (+ N n) n))
201
202 (let* ((n1 (f (if (eq? n1 None) 0 n1)))
203 (n2 (f (if (eq? n2 None) (slot-ref o 'n) n2)))
204 (n3 (f (if (eq? n3 None) 1 n3)))
205 (vec (slot-ref o 'vec))
206 (o2 (to-pylist val))
207 (N2 (slot-ref o2 'n))
208 (vec2 (slot-ref o2 'vec)))
209 (if (<= n2 N)
210 (let lp ((i 0) (j n1))
211 (if (< j n2)
212 (if (< i N2)
213 (begin
214 (vector-set! vec j (vector-ref vec2 i))
215 (lp (+ i 1) (+ j n3)))
216 (let lp ((j2 j))
217 (if (< j2 n2)
218 (lp (+ j2 n3))
219 (let lp ((k1 j) (k2 j2))
220 (if (< k2 N)
221 (begin
222 (vector-set! vec k1 (vector-ref vec k2))
223 (lp (+ k1 1) (+ k2 1)))
224 (begin
225 (let lp ((i k2))
226 (if (< i N)
227 (begin
228 (vector-set! vec i #f)
229 (lp (+ i 1)))
230 (slot-set! o 'n k1)))))))))))
231 (raise IndexError))
232 (values)))
233
234
235 ;;APPEND
236 (define-method (pylist-append! (o <py-list>) val)
237 (let* ((n (slot-ref o 'n))
238 (vec (slot-ref o 'vec))
239 (N (vector-length vec)))
240 (if (< n N)
241 (begin
242 (vector-set! vec n val)
243 (slot-set! o 'n (+ n 1)))
244 (let* ((N (* 2 N))
245 (vec2 (make-vector N)))
246 (let lp ((i 0))
247 (if (< i n)
248 (begin
249 (vector-set! vec2 i (vector-ref vec i))
250 (lp (+ i 1)))))
251 (vector-set! vec2 n val)
252 (slot-set! o 'vec vec2)))
253 (slot-set! o 'n (+ n 1))
254 (values)))
255
256 (define-method (pylist-append! o n)
257 (raise 'NotSupportedOP '__append__))
258
259 (define-method (pylist-append! (o <p>) n . l)
260 (aif it (ref o 'append)
261 (apply it n l)
262 (next-method)))
263
264
265
266 (define-method (write (o <py-list>) . l)
267 (define port (if (null? l) #t (car l)))
268
269 (let* ((l (to-list o)))
270 (if (null? l)
271 (format port "[]")
272 (format port "[~a~{, ~a~}]" (car l) (cdr l)))))
273
274 (define-method (display (o <py-list>) . l)
275 (define port (if (null? l) #t (car l)))
276
277 (let* ((l (to-list o)))
278 (if (null? l)
279 (format port "[]")
280 (format port "[~a~{, ~a~}]" (car l) (cdr l)))))
281
282
283 (define-method (+ (o1 <py-list>) (o2 <py-list>))
284 (let* ((vec1 (slot-ref o1 'vec))
285 (vec2 (slot-ref o2 'vec))
286 (n1 (slot-ref o1 'n))
287 (n2 (slot-ref o2 'n))
288 (n (+ n1 n2))
289 (vec (make-vector (* 2 n)))
290 (o (make <py-list>)))
291
292 (let lp ((i1 0))
293 (if (< i1 n1)
294 (begin
295 (vector-set! vec i1 (vector-ref vec1 i1))
296 (lp (+ i1 1)))
297 (let lp ((i2 0) (i i1))
298 (if (< i2 n2)
299 (begin
300 (vector-set! vec i (vector-ref vec2 i2))
301 (lp (+ i2 1) (+ i 1)))))))
302
303 (slot-set! o 'n n )
304 (slot-set! o 'vec vec)
305 o))
306
307
308 (define-method (+ (o1 <pair>) (o2 <pair>))
309 (append o1 o2))
310
311 (define-method (+ (o1 <string>) (o2 <string>))
312 (string-append o1 o2))
313
314 (define-method (+ (o1 <symbol>) (o2 <symbol>))
315 (string->symbol
316 (string-append
317 (symbol->string o1)
318 (symbol->string o2))))
319
320 (define-method (* (x <integer>) (o1 <py-list>)) (* o1 x))
321 (define-method (* (o1 <py-list>) (x <integer>))
322 (let* ((vec (slot-ref o1 'vec))
323 (n (slot-ref o1 'n))
324 (n2 (* n x))
325 (vec2 (make-vector (* 2 n2)))
326 (o (make <py-list>)))
327
328 (let lp1 ((i 0) (j 0))
329 (if (< i x)
330 (let lp2 ((j j) (k 0))
331 (if (< k n)
332 (begin
333 (vector-set! vec2 j (vector-ref vec k))
334 (lp2 (+ j 1) (+ k 1)))
335 (lp1 (+ i 1) j)))))
336
337 (slot-set! o 'n n2 )
338 (slot-set! o 'vec vec2)
339 o))
340
341 (define-method (* (x <integer>) (vec <string>)) (* vec x))
342 (define-method (* (vec <string>) (x <integer>))
343 (let* ((n (string-length vec))
344 (n2 (* n x))
345 (vec2 (make-string n2)))
346
347 (let lp1 ((i 0) (j 0))
348 (if (< i x)
349 (let lp2 ((j j) (k 0))
350 (if (< k n)
351 (begin
352 (string-set! vec2 j (string-ref vec k))
353 (lp2 (+ j 1) (+ k 1)))
354 (lp1 (+ i 1) j)))))
355 vec2))
356
357 (define-method (* (x <integer>) (l <pair>)) (* l x))
358 (define-method (* (l <pair>) (x <integer>))
359 (let lp1 ((i 0))
360 (if (< i x)
361 (let lp2 ((k l))
362 (if (pair? k)
363 (cons (car k) (lp2 (cdr k)))
364 (lp1 (+ i 1))))
365 '())))
366
367
368 ;;REVERSE
369 (define-method (pylist-reverse! (o <py-list>))
370 (let* ((N (slot-ref o 'n))
371 (M (- N 1))
372 (n (floor-quotient N 2))
373 (vec (slot-ref o 'vec)))
374 (let lp ((i 0))
375 (if (< i n)
376 (let ((swap (vector-ref vec i))
377 (k (- M i)))
378 (vector-set! vec i (vector-ref vec k))
379 (vector-set! vec k swap))))))
380
381
382 (define-method (pylist-reverse! (o <p>) . l)
383 (aif it (ref o 'reverse)
384 (apply it l)
385 (next-method)))
386
387 ;;POP!
388 (define-method (pylist-pop! (o <py-list>))
389 (let* ((n (slot-ref o 'n))
390 (m (- n 1))
391 (vec (slot-ref o 'vec)))
392 (if (> n 0)
393 (let ((ret (vector-ref vec m)))
394 (slot-set! o 'n m)
395 (vector-set! vec m #f)
396 ret)
397 (raise IndexError "pop from empty list"))))
398
399 (define-method (pylist-pop! (o <p>) . l)
400 (aif it (ref o 'pop)
401 (apply it l)
402 (next-method)))
403
404 ;;COUNT
405 (define-method (pylist-count (o <py-list>) q)
406 (let* ((n (slot-ref o 'n))
407 (vec (slot-ref o 'vec)))
408 (let lp ((i 0) (sum 0))
409 (if (< i n)
410 (if (equal? (vector-ref vec i) q)
411 (lp (+ i 1) (+ sum 1))
412 (lp (+ i 1) sum ))
413 sum))))
414
415 (define-method (pylist-count (s <string>) q)
416 (let* ((n (string-length s))
417 (q (if (and (string? q) (= (string-length q) 1))
418 (string-ref q 0))))
419 (let lp ((i 0) (sum 0))
420 (if (< i n)
421 (if (eq? (string-ref s i) q)
422 (lp (+ i 1) (+ sum 1))
423 (lp (+ i 1) sum ))
424 sum))))
425
426 (define-method (pylist-count (l <pair>) q)
427 (let lp ((l l) (sum 0))
428 (if (pair? l)
429 (if (eq? (car l) q)
430 (lp (cdr l) (+ sum 1))
431 (lp (cdr l) sum ))
432 sum)))
433
434 (define-method (pylist-count (o <p>) . l)
435 (aif it (ref o 'count)
436 (apply it l)
437 (next-method)))
438
439 ;; extend!
440 (define-method (pylist-extend! (o <py-list>) iter)
441 (for ((x : iter)) ()
442 (pylist-append! o x)))
443
444 (define-method (pylist-extend! (o <p>) . l)
445 (aif it (ref o 'extend)
446 (apply it l)
447 (next-method)))
448
449 ;; equal?
450 (define-method (equal? (o1 <py-list>) (o2 <py-list>))
451 (let ((n1 (slot-ref o1 'n))
452 (n2 (slot-ref o2 'n))
453 (vec1 (slot-ref o1 'vec))
454 (vec2 (slot-ref o2 'vec)))
455 (and
456 (equal? n1 n2)
457 (let lp ((i 0))
458 (if (< i n1)
459 (and (equal? (vector-ref vec1 i) (vector-ref vec2 i))
460 (lp (+ i 1)))
461 #t)))))
462
463 (define-method (equal? (o1 <py-list>) o2) #f)
464 (define-method (equal? o1 (o2 <py-list>)) #f)
465
466
467 (define-class <py-list-iter> (<py-list>) i)
468 (define-class <string-iter> () str i)
469
470 ;;WRAP-IN
471 (define-method (wrap-in (s <string>))
472 (let ((out (make <string-iter>)))
473 (slot-set! out 'str s)
474 (slot-set! out 'i 0)
475 out))
476
477 (define-method (wrap-in (o <py-list>))
478 (let ((out (make <py-list-iter>)))
479 (slot-set! out 'n (slot-ref o 'n ))
480 (slot-set! out 'vec (slot-ref o 'vec))
481 (slot-set! out 'i 0)
482 out))
483
484 (define-method (wrap-in (o <py-list-iter>)) o)
485 (define-method (wrap-in (o <string-iter> )) o)
486 ;;NEXT
487 (define-method (next (o <string-iter>))
488 (let ((i (slot-ref o 'i ))
489 (str (slot-ref o 'str)))
490 (if (< i (string-length str))
491 (let ((ret (string-ref str i)))
492 (slot-set! o 'i (+ i 1))
493 (list->string (scm-list ret)))
494 (throw StopIteration))))
495
496 (define-method (next (o <py-list-iter>))
497 (let ((i (slot-ref o 'i ))
498 (n (slot-ref o 'n ))
499 (vec (slot-ref o 'vec)))
500 (if (< i n)
501 (let ((ret (vector-ref vec i)))
502 (slot-set! o 'i (+ i 1))
503 ret)
504 (throw StopIteration))))
505
506 ;;INSERT
507 (define-method (pylist-insert! (o <py-list>) i val)
508 (let* ((vec (slot-ref o 'vec))
509 (n (slot-ref o 'n))
510 (i (if (< i 0) (+ n i) i)))
511 (if (and (>= i 0) (<= i n))
512 (let lp ((v val) (i i))
513 (if (< i n)
514 (let ((swap (vector-ref vec i)))
515 (vector-set! vec i v)
516 (lp swap (+ i 1)))
517 (pylist-append! o v)))
518 (raise IndexError "Wrong index in insert"))))
519
520 (define-method (pylist-insert! (o <p>) . l)
521 (aif it (ref o 'insert)
522 (apply it l)
523 (next-method)))
524
525
526 ;;REMOVE
527 (define-method (pylist-remove! (o <py-list>) val)
528 (let ((n (slot-ref o 'n ))
529 (vec (slot-ref o 'vec)))
530 (let lp ((i 0))
531 (if (< i n)
532 (let ((r (vector-ref vec i)))
533 (if (equal? r val)
534 (pylist-subset! o i (+ i 1) 1 '())
535 (lp (+ i 1))))
536 (raise ValueError "list removal has no element to remove")))))
537
538 (define-method (pylist-remove! (o <p>) . l)
539 (aif it (ref o 'remove)
540 (apply it l)
541 (next-method)))
542
543 ;; SORT!
544 (define (id x) id)
545 (define-method (pylist-sort! (o <py-list>) . l)
546 (apply
547 (lambda* (#:key (key id) (reverse #f))
548 (let lp ((l (sort (map key (to-list o)) (if reverse > <))) (i 0))
549 (if (pair? l)
550 (begin
551 (pylist-set! o i (car l))
552 (lp (cdr l) (+ i 1))))))
553 l))
554
555 (define-method (pylist-sort! (o <p>) . l)
556 (aif it (ref o 'sort)
557 (apply it l)
558 (next-method)))
559
560 ;; INDEX
561 (define-method (pylist-index (o <py-list>) val . l)
562 (let* ((n (slot-ref o 'n ))
563 (vec (slot-ref o 'vec))
564 (f (lambda (m) (if (< m 0) (+ m n) m))))
565 (call-with-values
566 (lambda ()
567 (match l
568 (()
569 (values 0 n))
570 ((x)
571 (values (f x) n))
572 ((x y)
573 (values (f x) (f y)))))
574 (lambda (n1 n2)
575 (if (and (>= n1 0) (>= n2 0) (< n1 n) (<= n2 n))
576 (let lp ((i n1))
577 (if (< i n2)
578 (let ((r (vector-ref vec i)))
579 (if (equal? r val)
580 i
581 (lp (+ i 1))))
582 (raise ValueError "could not find value in index fkn")))
583 (raise IndexError "index out of scop in index fkn"))))))
584
585 (define-method (pylist-index (o <string>) val . l)
586 (let* ((n (string-length o))
587 (f (lambda (m) (if (< m 0) (+ m n) m)))
588 (val (if (and (string? val) (> (string-length val) 0))
589 (string-ref val 0)
590 val)))
591 (call-with-values
592 (lambda ()
593 (match l
594 (()
595 (values 0 n))
596 ((x)
597 (values (f x) n))
598 ((x y)
599 (values (f x) (f y)))))
600 (lambda (n1 n2)
601 (if (and (>= n1 0) (>= n2 0) (< n1 n) (<= n2 n))
602 (let lp ((i n1))
603 (if (< i n2)
604 (let ((r (string-ref o i)))
605 (if (equal? r val)
606 i
607 (lp (+ i 1))))
608 (raise ValueError "could not find value in index fkn")))
609 (raise IndexError "index out of scop in index fkn"))))))
610
611 (define-method (pylist-index (o <pair>) val . l)
612 (let* ((n (length o))
613 (f (lambda (m) (if (< m 0) (+ m n) m))))
614 (call-with-values
615 (lambda ()
616 (match l
617 (()
618 (values 0 n))
619 ((x)
620 (values (f x) n))
621 ((x y)
622 (values (f x) (f y)))))
623 (lambda (n1 n2)
624 (if (and (>= n1 0) (>= n2 0) (< n1 n) (<= n2 n))
625 (let lp ((i o))
626 (if (pair? i)
627 (let ((r (car i)))
628 (if (equal? r val)
629 i
630 (lp (cdr i))))
631 (raise ValueError "could not find value in index fkn")))
632 (raise IndexError "index out of scop in index fkn"))))))
633
634 (define-method (pylist-index (o <p>) . l)
635 (aif it (ref o 'index)
636 (apply it l)
637 (next-method)))
638
639
640 #:len
641
642 (define-method (len (l <pair> )) (length l))
643 (define-method (len (v <vector>)) (vector-length v))
644 (define-method (len (s <string>)) (string-length s))
645 (define-method (len (o <py-list>)) (slot-ref o 'n))
646 (define-method (len (o <p>))
647 (aif it (ref o '__len__)
648 (it)
649 (next-method)))
650
651 (define-method (in x (l <pair>)) (member x l))
652 (define-method (in x (l <vector>))
653 (define n (vector-length l))
654 (let lp ((i 0))
655 (if (< i n)
656 (if (equal? x (vector-ref l i))
657 #t
658 (lp (+ i 1)))
659 #f)))
660
661 (define-method (in x (s <string>))
662 (let ((n (string-length s))
663 (x (if (string? x) (string-ref x 0) x)))
664 (let lp ((i 0))
665 (if (< i n)
666 (if (equal? x (string-ref s i))
667 #t
668 (lp (+ i 1)))
669 #f))))
670
671 (define-method (in x (o <py-list>))
672 (define l (slot-ref o 'vec))
673 (define n (slot-ref o 'n))
674 (let lp ((i 0))
675 (if (< i n)
676 (if (equal? x (vector-ref l i))
677 #t
678 (lp (+ i 1)))
679 #f)))
680
681 (define-method (in x (o <p>))
682 (aif it (ref o '__contains__)
683 (it x)
684 (next-method)))
685
686 (define-syntax-rule (defgen (op o1 o2) code ...)
687 (begin
688 (define-method (op (o1 <py-list>) (o2 <py-list>)) code ...)
689 (define-method (op (o1 <pair>) (o2 <pair> )) code ...)
690 (define-method (op (o1 <vector>) (o2 <vector>)) code ...)
691 (define-method (op (o1 <p>) o2)
692 (aif it (ref o1 'r)
693 (it o2)
694 (next-method)))))
695
696 (defgen (< o1 o2)
697 (let ((n1 (len o1))
698 (n2 (len o2)))
699 (for ((x1 : o1) (x2 : o2)) ()
700 (if (< x1 x2)
701 (break #t))
702 #:final
703 (< n1 n2))))
704
705 (defgen (<= o1 o2)
706 (let ((n1 (len o1))
707 (n2 (len o2)))
708 (for ((x1 : o1) (x2 : o2)) ()
709 (if (< x1 x2)
710 (break #t))
711 #:final
712 (<= n1 n2))))
713
714 (defgen (> o1 o2)
715 (let ((n1 (len o1))
716 (n2 (len o2)))
717 (for ((x1 : o1) (x2 : o2)) ()
718 (if (> x1 x2)
719 (break #t))
720 #:final
721 (> n1 n2))))
722
723 (defgen (>= o1 o2)
724 (let ((n1 (len o1))
725 (n2 (len o2)))
726 (for ((x1 : o1) (x2 : o2)) ()
727 (if (> x1 x2)
728 (break #t))
729 #:final
730 (>= n1 n2))))
731
732 (define-python-class list (<py-list>)
733 (define __init__
734 (letrec ((__init__
735 (case-lambda
736 ((self)
737 (slot-set! self 'vec (make-vector 30))
738 (slot-set! self 'n 0))
739 ((self it)
740 (__init__ self)
741 (for ((i : it)) () (pylist-append! self i))))))
742 __init__)))
743
744 (define pylist list)
745
746
747 (define-method (py-class (o <py-list>) list))
748
749 (define (pylist-listing)
750 (let ((l
751 (to-pylist
752 (map symbol->string
753 '(append
754 count
755 extend
756 index
757 pop
758 insert
759 remove
760 reverse
761 sort
762 __init__
763 __le__
764 __lt__
765 __gt__
766 __ge__
767 __ne__
768 __eq__
769 __len__
770 __init__
771 __add__
772 __mul__
773 __rmul__
774 __radd__
775 __repr__
776 __contains__
777 __getattr__
778 __setattr__
779 __delattr__
780 __delitem__
781 __setitem__
782 __iter__
783 )))))
784
785 (pylist-sort! l)
786 l))
787
788 (define (py-all x)
789 (for ((i : x)) ()
790 (if (not i)
791 (break #f))
792 #:final
793 #t))
794
795 (define (py-any x)
796 (for ((i : x)) ()
797 (if i
798 (break #t))
799 #:final
800 #f))
801
802
803