Debian Codegraph @

%3a42/examples.scm

raw
1 ; <PLAINTEXT>
2 ; Examples for Eager Comprehensions in [outer..inner|expr]-Convention
3 ; ===================================================================
4 ;
5 ; [email protected], Eindhoven, The Netherlands, 26-Dec-2007.
6 ; Scheme R5RS (incl. macros), SRFI-23 (error).
7 ;
8 ; Running the examples in Scheme48 (version 1.1):
9 ; ,open srfi-23
10 ; ,load ec.scm
11 ; (define my-open-output-file open-output-file)
12 ; (define my-call-with-input-file call-with-input-file)
13 ; ,load examples.scm
14 ;
15 ; Running the examples in PLT/DrScheme (version 317):
16 ; (load "ec.scm")
17 ; (define (my-open-output-file filename)
18 ; (open-output-file filename 'replace 'text) )
19 ; (define (my-call-with-input-file filename thunk)
20 ; (call-with-input-file filename thunk 'text) )
21 ; (load "examples.scm")
22 ;
23 ; Running the examples in SCM (version 5d7):
24 ; (require 'macro) (require 'record)
25 ; (load "ec.scm")
26 ; (define my-open-output-file open-output-file)
27 ; (define my-call-with-input-file call-with-input-file)
28 ; (load "examples.scm")
29
30
31 ; Tools for checking results
32 ; ==========================
33
34 (define (my-equal? x y)
35 (cond
36 ((or (boolean? x)
37 (null? x)
38 (symbol? x)
39 (char? x)
40 (input-port? x)
41 (output-port? x) )
42 (eqv? x y) )
43 ((string? x)
44 (and (string? y) (string=? x y)) )
45 ((vector? x)
46 (and (vector? y)
47 (my-equal? (vector->list x) (vector->list y)) ))
48 ((pair? x)
49 (and (pair? y)
50 (my-equal? (car x) (car y))
51 (my-equal? (cdr x) (cdr y)) ))
52 ((real? x)
53 (and (real? y)
54 (eqv? (exact? x) (exact? y))
55 (if (exact? x)
56 (= x y)
57 (< (abs (- x y)) (/ 1 (expt 10 6))) ))) ; will do here
58 (else
59 (error "unrecognized type" x) )))
60
61 (define my-check-correct 0)
62 (define my-check-wrong 0)
63
64 (define-syntax my-check
65 (syntax-rules (=>)
66 ((my-check ec => desired-result)
67 (begin
68 (newline)
69 (write (quote ec))
70 (newline)
71 (let ((actual-result ec))
72 (display " => ")
73 (write actual-result)
74 (if (my-equal? actual-result desired-result)
75 (begin
76 (display " ; correct")
77 (set! my-check-correct (+ my-check-correct 1)) )
78 (begin
79 (display " ; *** wrong ***, desired result:")
80 (newline)
81 (display " => ")
82 (write desired-result)
83 (set! my-check-wrong (+ my-check-wrong 1)) ))
84 (newline) )))))
85
86
87 ; ==========================================================================
88 ; do-ec
89 ; ==========================================================================
90
91 (my-check
92 (let ((x 0)) (do-ec (set! x (+ x 1))) x)
93 => 1)
94
95 (my-check
96 (let ((x 0)) (do-ec (:range i 10) (set! x (+ x 1))) x)
97 => 10)
98
99 (my-check
100 (let ((x 0)) (do-ec (:range n 10) (:range k n) (set! x (+ x 1))) x)
101 => 45)
102
103
104 ; ==========================================================================
105 ; list-ec and basic qualifiers
106 ; ==========================================================================
107
108 (my-check (list-ec 1) => '(1))
109
110 (my-check (list-ec (:range i 4) i) => '(0 1 2 3))
111
112 (my-check (list-ec (:range n 3) (:range k (+ n 1)) (list n k))
113 => '((0 0) (1 0) (1 1) (2 0) (2 1) (2 2)) )
114
115 (my-check
116 (list-ec (:range n 5) (if (even? n)) (:range k (+ n 1)) (list n k))
117 => '((0 0) (2 0) (2 1) (2 2) (4 0) (4 1) (4 2) (4 3) (4 4)) )
118
119 (my-check
120 (list-ec (:range n 5) (not (even? n)) (:range k (+ n 1)) (list n k))
121 => '((1 0) (1 1) (3 0) (3 1) (3 2) (3 3)) )
122
123 (my-check
124 (list-ec (:range n 5)
125 (and (even? n) (> n 2))
126 (:range k (+ n 1))
127 (list n k) )
128 => '((4 0) (4 1) (4 2) (4 3) (4 4)) )
129
130 (my-check
131 (list-ec (:range n 5)
132 (or (even? n) (> n 3))
133 (:range k (+ n 1))
134 (list n k) )
135 => '((0 0) (2 0) (2 1) (2 2) (4 0) (4 1) (4 2) (4 3) (4 4)) )
136
137 (my-check
138 (let ((x 0)) (list-ec (:range n 10) (begin (set! x (+ x 1))) n) x)
139 => 10 )
140
141 (my-check
142 (list-ec (nested (:range n 3) (:range k n)) k)
143 => '(0 0 1) )
144
145
146 ; ==========================================================================
147 ; Other comprehensions
148 ; ==========================================================================
149
150 (my-check (append-ec '(a b)) => '(a b))
151 (my-check (append-ec (:range i 0) '(a b)) => '())
152 (my-check (append-ec (:range i 1) '(a b)) => '(a b))
153 (my-check (append-ec (:range i 2) '(a b)) => '(a b a b))
154
155 (my-check (string-ec #\a) => (string #\a))
156 (my-check (string-ec (:range i 0) #\a) => "")
157 (my-check (string-ec (:range i 1) #\a) => "a")
158 (my-check (string-ec (:range i 2) #\a) => "aa")
159
160 (my-check (string-append-ec "ab") => "ab")
161 (my-check (string-append-ec (:range i 0) "ab") => "")
162 (my-check (string-append-ec (:range i 1) "ab") => "ab")
163 (my-check (string-append-ec (:range i 2) "ab") => "abab")
164
165 (my-check (vector-ec 1) => (vector 1))
166 (my-check (vector-ec (:range i 0) i) => (vector))
167 (my-check (vector-ec (:range i 1) i) => (vector 0))
168 (my-check (vector-ec (:range i 2) i) => (vector 0 1))
169
170 (my-check (vector-of-length-ec 1 1) => (vector 1))
171 (my-check (vector-of-length-ec 0 (:range i 0) i) => (vector))
172 (my-check (vector-of-length-ec 1 (:range i 1) i) => (vector 0))
173 (my-check (vector-of-length-ec 2 (:range i 2) i) => (vector 0 1))
174
175 (my-check (sum-ec 1) => 1)
176 (my-check (sum-ec (:range i 0) i) => 0)
177 (my-check (sum-ec (:range i 1) i) => 0)
178 (my-check (sum-ec (:range i 2) i) => 1)
179 (my-check (sum-ec (:range i 3) i) => 3)
180
181 (my-check (product-ec 1) => 1)
182 (my-check (product-ec (:range i 1 0) i) => 1)
183 (my-check (product-ec (:range i 1 1) i) => 1)
184 (my-check (product-ec (:range i 1 2) i) => 1)
185 (my-check (product-ec (:range i 1 3) i) => 2)
186 (my-check (product-ec (:range i 1 4) i) => 6)
187
188 (my-check (min-ec 1) => 1)
189 (my-check (min-ec (:range i 1) i) => 0)
190 (my-check (min-ec (:range i 2) i) => 0)
191
192 (my-check (max-ec 1) => 1)
193 (my-check (max-ec (:range i 1) i) => 0)
194 (my-check (max-ec (:range i 2) i) => 1)
195
196 (my-check (first-ec #f 1) => 1)
197 (my-check (first-ec #f (:range i 0) i) => #f)
198 (my-check (first-ec #f (:range i 1) i) => 0)
199 (my-check (first-ec #f (:range i 2) i) => 0)
200
201 (my-check
202 (let ((last-i -1))
203 (first-ec #f (:range i 10) (begin (set! last-i i)) i)
204 last-i )
205 => 0 )
206
207 (my-check (last-ec #f 1) => 1)
208 (my-check (last-ec #f (:range i 0) i) => #f)
209 (my-check (last-ec #f (:range i 1) i) => 0)
210 (my-check (last-ec #f (:range i 2) i) => 1)
211
212 (my-check (any?-ec #f) => #f)
213 (my-check (any?-ec #t) => #t)
214 (my-check (any?-ec (:range i 2 2) (even? i)) => #f)
215 (my-check (any?-ec (:range i 2 3) (even? i)) => #t)
216
217 (my-check (every?-ec #f) => #f)
218 (my-check (every?-ec #t) => #t)
219 (my-check (every?-ec (:range i 2 2) (even? i)) => #t)
220 (my-check (every?-ec (:range i 2 3) (even? i)) => #t)
221 (my-check (every?-ec (:range i 2 4) (even? i)) => #f)
222
223 (my-check
224 (let ((sum-sqr (lambda (x result) (+ result (* x x)))))
225 (fold-ec 0 (:range i 10) i sum-sqr) )
226 => 285 )
227
228 (my-check
229 (let ((minus-1 (lambda (x) (- x 1)))
230 (sum-sqr (lambda (x result) (+ result (* x x)))))
231 (fold3-ec (error "wrong") (:range i 10) i minus-1 sum-sqr) )
232 => 284 )
233
234 (my-check
235 (fold3-ec 'infinity (:range i 0) i min min)
236 => 'infinity )
237
238
239 ; ==========================================================================
240 ; Typed generators
241 ; ==========================================================================
242
243 (my-check (list-ec (:list x '()) x) => '())
244 (my-check (list-ec (:list x '(1)) x) => '(1))
245 (my-check (list-ec (:list x '(1 2 3)) x) => '(1 2 3))
246 (my-check (list-ec (:list x '(1) '(2)) x) => '(1 2))
247 (my-check (list-ec (:list x '(1) '(2) '(3)) x) => '(1 2 3))
248
249 (my-check (list-ec (:string c "") c) => '())
250 (my-check (list-ec (:string c "1") c) => '(#\1))
251 (my-check (list-ec (:string c "123") c) => '(#\1 #\2 #\3))
252 (my-check (list-ec (:string c "1" "2") c) => '(#\1 #\2))
253 (my-check (list-ec (:string c "1" "2" "3") c) => '(#\1 #\2 #\3))
254
255 (my-check (list-ec (:vector x (vector)) x) => '())
256 (my-check (list-ec (:vector x (vector 1)) x) => '(1))
257 (my-check (list-ec (:vector x (vector 1 2 3)) x) => '(1 2 3))
258 (my-check (list-ec (:vector x (vector 1) (vector 2)) x) => '(1 2))
259 (my-check
260 (list-ec (:vector x (vector 1) (vector 2) (vector 3)) x)
261 => '(1 2 3))
262
263 (my-check (list-ec (:range x -2) x) => '())
264 (my-check (list-ec (:range x -1) x) => '())
265 (my-check (list-ec (:range x 0) x) => '())
266 (my-check (list-ec (:range x 1) x) => '(0))
267 (my-check (list-ec (:range x 2) x) => '(0 1))
268
269 (my-check (list-ec (:range x 0 3) x) => '(0 1 2))
270 (my-check (list-ec (:range x 1 3) x) => '(1 2))
271 (my-check (list-ec (:range x -2 -1) x) => '(-2))
272 (my-check (list-ec (:range x -2 -2) x) => '())
273
274 (my-check (list-ec (:range x 1 5 2) x) => '(1 3))
275 (my-check (list-ec (:range x 1 6 2) x) => '(1 3 5))
276 (my-check (list-ec (:range x 5 1 -2) x) => '(5 3))
277 (my-check (list-ec (:range x 6 1 -2) x) => '(6 4 2))
278
279 (my-check (list-ec (:real-range x 0.0 3.0) x) => '(0. 1. 2.))
280 (my-check (list-ec (:real-range x 0 3.0) x) => '(0. 1. 2.))
281 (my-check (list-ec (:real-range x 0 3 1.0) x) => '(0. 1. 2.))
282
283 (my-check
284 (string-ec (:char-range c #\a #\z) c)
285 => "abcdefghijklmnopqrstuvwxyz" )
286
287 (my-check
288 (begin
289 (let ((f (my-open-output-file "tmp1")))
290 (do-ec (:range n 10) (begin (write n f) (newline f)))
291 (close-output-port f))
292 (my-call-with-input-file "tmp1"
293 (lambda (port) (list-ec (:port x port read) x)) ))
294 => (list-ec (:range n 10) n) )
295
296 (my-check
297 (begin
298 (let ((f (my-open-output-file "tmp1")))
299 (do-ec (:range n 10) (begin (write n f) (newline f)))
300 (close-output-port f))
301 (my-call-with-input-file "tmp1"
302 (lambda (port) (list-ec (:port x port) x)) ))
303 => (list-ec (:range n 10) n) )
304
305
306 ; ==========================================================================
307 ; The special generators :do :let :parallel :while :until
308 ; ==========================================================================
309
310 (my-check (list-ec (:do ((i 0)) (< i 4) ((+ i 1))) i) => '(0 1 2 3))
311
312 (my-check
313 (list-ec
314 (:do (let ((x 'x)))
315 ((i 0))
316 (< i 4)
317 (let ((j (- 10 i))))
318 #t
319 ((+ i 1)) )
320 j )
321 => '(10 9 8 7) )
322
323 (my-check (list-ec (:let x 1) x) => '(1))
324 (my-check (list-ec (:let x 1) (:let y (+ x 1)) y) => '(2))
325 (my-check (list-ec (:let x 1) (:let x (+ x 1)) x) => '(2))
326
327 (my-check
328 (list-ec (:parallel (:range i 1 10) (:list x '(a b c))) (list i x))
329 => '((1 a) (2 b) (3 c)) )
330
331 (my-check
332 (list-ec (:while (:range i 1 10) (< i 5)) i)
333 => '(1 2 3 4) )
334
335 (my-check
336 (list-ec (:until (:range i 1 10) (>= i 5)) i)
337 => '(1 2 3 4 5) )
338
339 ; with generator that might use inner bindings
340
341 (my-check
342 (list-ec (:while (:list i '(1 2 3 4 5 6 7 8 9)) (< i 5)) i)
343 => '(1 2 3 4) )
344 ; Was broken in original reference implementation as pointed
345 ; out by [email protected] on 24-Apr-2005 comp.lang.scheme.
346 ; Refer to http://groups-beta.google.com/group/comp.lang.scheme/
347 ; browse_thread/thread/f5333220eaeeed66/75926634cf31c038#75926634cf31c038
348
349 (my-check
350 (list-ec (:until (:list i '(1 2 3 4 5 6 7 8 9)) (>= i 5)) i)
351 => '(1 2 3 4 5) )
352
353 (my-check
354 (list-ec (:while (:vector x (index i) '#(1 2 3 4 5))
355 (< x 10))
356 x)
357 => '(1 2 3 4 5))
358 ; Was broken in reference implementation, even after fix for the
359 ; bug reported by Sunnan, as reported by Jens-Axel Soegaard on
360 ; 4-Jun-2007.
361
362 ; combine :while/:until and :parallel
363
364 (my-check
365 (list-ec (:while (:parallel (:range i 1 10)
366 (:list j '(1 2 3 4 5 6 7 8 9)))
367 (< i 5))
368 (list i j))
369 => '((1 1) (2 2) (3 3) (4 4)))
370
371 (my-check
372 (list-ec (:until (:parallel (:range i 1 10)
373 (:list j '(1 2 3 4 5 6 7 8 9)))
374 (>= i 5))
375 (list i j))
376 => '((1 1) (2 2) (3 3) (4 4) (5 5)))
377
378 ; check that :while/:until really stop the generator
379
380 (my-check
381 (let ((n 0))
382 (do-ec (:while (:range i 1 10) (begin (set! n (+ n 1)) (< i 5)))
383 (if #f #f))
384 n)
385 => 5)
386
387 (my-check
388 (let ((n 0))
389 (do-ec (:until (:range i 1 10) (begin (set! n (+ n 1)) (>= i 5)))
390 (if #f #f))
391 n)
392 => 5)
393
394 (my-check
395 (let ((n 0))
396 (do-ec (:while (:parallel (:range i 1 10)
397 (:do () (begin (set! n (+ n 1)) #t) ()))
398 (< i 5))
399 (if #f #f))
400 n)
401 => 5)
402
403 (my-check
404 (let ((n 0))
405 (do-ec (:until (:parallel (:range i 1 10)
406 (:do () (begin (set! n (+ n 1)) #t) ()))
407 (>= i 5))
408 (if #f #f))
409 n)
410 => 5)
411
412 ; ==========================================================================
413 ; The dispatching generator
414 ; ==========================================================================
415
416 (my-check (list-ec (: c '(a b)) c) => '(a b))
417 (my-check (list-ec (: c '(a b) '(c d)) c) => '(a b c d))
418
419 (my-check (list-ec (: c "ab") c) => '(#\a #\b))
420 (my-check (list-ec (: c "ab" "cd") c) => '(#\a #\b #\c #\d))
421
422 (my-check (list-ec (: c (vector 'a 'b)) c) => '(a b))
423 (my-check (list-ec (: c (vector 'a 'b) (vector 'c)) c) => '(a b c))
424
425 (my-check (list-ec (: i 0) i) => '())
426 (my-check (list-ec (: i 1) i) => '(0))
427 (my-check (list-ec (: i 10) i) => '(0 1 2 3 4 5 6 7 8 9))
428 (my-check (list-ec (: i 1 2) i) => '(1))
429 (my-check (list-ec (: i 1 2 3) i) => '(1))
430 (my-check (list-ec (: i 1 9 3) i) => '(1 4 7))
431
432 (my-check (list-ec (: i 0.0 1.0 0.2) i) => '(0. 0.2 0.4 0.6 0.8))
433
434 (my-check (list-ec (: c #\a #\c) c) => '(#\a #\b #\c))
435
436 (my-check
437 (begin
438 (let ((f (my-open-output-file "tmp1")))
439 (do-ec (:range n 10) (begin (write n f) (newline f)))
440 (close-output-port f))
441 (my-call-with-input-file "tmp1"
442 (lambda (port) (list-ec (: x port read) x)) ))
443 => (list-ec (:range n 10) n) )
444
445 (my-check
446 (begin
447 (let ((f (my-open-output-file "tmp1")))
448 (do-ec (:range n 10) (begin (write n f) (newline f)))
449 (close-output-port f))
450 (my-call-with-input-file "tmp1"
451 (lambda (port) (list-ec (: x port) x)) ))
452 => (list-ec (:range n 10) n) )
453
454
455 ; ==========================================================================
456 ; With index variable
457 ; ==========================================================================
458
459 (my-check (list-ec (:list c (index i) '(a b)) (list c i)) => '((a 0) (b 1)))
460 (my-check (list-ec (:string c (index i) "a") (list c i)) => '((#\a 0)))
461 (my-check (list-ec (:vector c (index i) (vector 'a)) (list c i)) => '((a 0)))
462
463 (my-check
464 (list-ec (:range i (index j) 0 -3 -1) (list i j))
465 => '((0 0) (-1 1) (-2 2)) )
466
467 (my-check
468 (list-ec (:real-range i (index j) 0 1 0.2) (list i j))
469 => '((0. 0) (0.2 1) (0.4 2) (0.6 3) (0.8 4)) )
470
471 (my-check
472 (list-ec (:char-range c (index i) #\a #\c) (list c i))
473 => '((#\a 0) (#\b 1) (#\c 2)) )
474
475 (my-check
476 (list-ec (: x (index i) '(a b c d)) (list x i))
477 => '((a 0) (b 1) (c 2) (d 3)) )
478
479 (my-check
480 (begin
481 (let ((f (my-open-output-file "tmp1")))
482 (do-ec (:range n 10) (begin (write n f) (newline f)))
483 (close-output-port f))
484 (my-call-with-input-file "tmp1"
485 (lambda (port) (list-ec (: x (index i) port) (list x i))) ))
486 => '((0 0) (1 1) (2 2) (3 3) (4 4) (5 5) (6 6) (7 7) (8 8) (9 9)) )
487
488
489 ; ==========================================================================
490 ; The examples from the SRFI document
491 ; ==========================================================================
492
493 ; from Abstract
494
495 (my-check (list-ec (: i 5) (* i i)) => '(0 1 4 9 16))
496
497 (my-check
498 (list-ec (: n 1 4) (: i n) (list n i))
499 => '((1 0) (2 0) (2 1) (3 0) (3 1) (3 2)) )
500
501 ; from Generators
502
503 (my-check
504 (list-ec (: x (index i) "abc") (list x i))
505 => '((#\a 0) (#\b 1) (#\c 2)) )
506
507 (my-check
508 (list-ec (:string c (index i) "a" "b") (cons c i))
509 => '((#\a . 0) (#\b . 1)) )
510
511
512 ; ==========================================================================
513 ; Little Shop of Horrors
514 ; ==========================================================================
515
516 (my-check (list-ec (:range x 5) (:range x x) x) => '(0 0 1 0 1 2 0 1 2 3))
517
518 (my-check (list-ec (:list x '(2 "23" (4))) (: y x) y) => '(0 1 #\2 #\3 4))
519
520 (my-check
521 (list-ec (:parallel (:integers x)
522 (:do ((i 10)) (< x i) ((- i 1))))
523 (list x i))
524 => '((0 10) (1 9) (2 8) (3 7) (4 6)) )
525
526
527 ; ==========================================================================
528 ; Less artificial examples
529 ; ==========================================================================
530
531 (define (factorial n) ; n * (n-1) * .. * 1 for n >= 0
532 (product-ec (:range k 2 (+ n 1)) k) )
533
534 (my-check (factorial 0) => 1)
535 (my-check (factorial 1) => 1)
536 (my-check (factorial 3) => 6)
537 (my-check (factorial 5) => 120)
538
539
540 (define (eratosthenes n) ; primes in {2..n-1} for n >= 1
541 (let ((p? (make-string n #\1)))
542 (do-ec (:range k 2 n)
543 (if (char=? (string-ref p? k) #\1))
544 (:range i (* 2 k) n k)
545 (string-set! p? i #\0) )
546 (list-ec (:range k 2 n) (if (char=? (string-ref p? k) #\1)) k) ))
547
548 (my-check
549 (eratosthenes 50)
550 => '(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47) )
551
552 (my-check
553 (length (eratosthenes 100000))
554 => 9592 ) ; we expect 10^5/ln(10^5)
555
556
557 (define (pythagoras n) ; a, b, c s.t. 1 <= a <= b <= c <= n, a^2 + b^2 = c^2
558 (list-ec
559 (:let sqr-n (* n n))
560 (:range a 1 (+ n 1))
561 ; (begin (display a) (display " "))
562 (:let sqr-a (* a a))
563 (:range b a (+ n 1))
564 (:let sqr-c (+ sqr-a (* b b)))
565 (if (<= sqr-c sqr-n))
566 (:range c b (+ n 1))
567 (if (= (* c c) sqr-c))
568 (list a b c) ))
569
570 (my-check
571 (pythagoras 15)
572 => '((3 4 5) (5 12 13) (6 8 10) (9 12 15)) )
573
574 (my-check
575 (length (pythagoras 200))
576 => 127 )
577
578
579 (define (qsort xs) ; stable
580 (if (null? xs)
581 '()
582 (let ((pivot (car xs)) (xrest (cdr xs)))
583 (append
584 (qsort (list-ec (:list x xrest) (if (< x pivot)) x))
585 (list pivot)
586 (qsort (list-ec (:list x xrest) (if (>= x pivot)) x)) ))))
587
588 (my-check
589 (qsort '(1 5 4 2 4 5 3 2 1 3))
590 => '(1 1 2 2 3 3 4 4 5 5) )
591
592
593 (define (pi-BBP m) ; approx. of pi within 16^-m (Bailey-Borwein-Plouffe)
594 (sum-ec
595 (:range n 0 (+ m 1))
596 (:let n8 (* 8 n))
597 (* (- (/ 4 (+ n8 1))
598 (+ (/ 2 (+ n8 4))
599 (/ 1 (+ n8 5))
600 (/ 1 (+ n8 6))))
601 (/ 1 (expt 16 n)) )))
602
603 (my-check
604 (pi-BBP 5)
605 => (/ 40413742330349316707 12864093722915635200) )
606
607
608 (define (read-line port) ; next line (incl. #\newline) of port
609 (let ((line
610 (string-ec
611 (:until (:port c port read-char)
612 (char=? c #\newline) )
613 c )))
614 (if (string=? line "")
615 (read-char port) ; eof-object
616 line )))
617
618 (define (read-lines filename) ; list of all lines
619 (my-call-with-input-file
620 filename
621 (lambda (port)
622 (list-ec (:port line port read-line) line) )))
623
624 (my-check
625 (begin
626 (let ((f (my-open-output-file "tmp1")))
627 (do-ec (:range n 10) (begin (write n f) (newline f)))
628 (close-output-port f))
629 (read-lines "tmp1") )
630 => (list-ec (:char-range c #\0 #\9) (string c #\newline)) )
631
632
633 ; ==========================================================================
634 ; Summary
635 ; ==========================================================================
636
637 (begin
638 (newline)
639 (newline)
640 (display "correct examples : ")
641 (display my-check-correct)
642 (newline)
643 (display "wrong examples : ")
644 (display my-check-wrong)
645 (newline)
646 (newline) )