Add debug statements in rpc-stream-map-sum example
[guile-orca] / examples / rpc-stream-map-sum.scm
1 #!/usr/bin/env -S guile -s
2 !#
3
4 (add-to-load-path "..")
5 (use-modules (orca))
6 (use-modules (ice-9 streams))
7
8 (define stream-add-two (make-stream (lambda (state)
9                                       (if (> state (* 2 (rpc-worker-process-size)))
10                                         '()
11                                         (cons state (+ state 2))))
12                          (rpc-worker-process-id)))
13
14 (define stream-add-one (make-stream (lambda (state)
15                                      (if (> state (* 2 (rpc-worker-process-size)))
16                                        '()
17                                        (cons state (+ state 1))))
18                         (rpc-worker-process-id)))
19
20 (define counter 0)
21
22 (define (sum-all return a b)
23  (format #t "a: ~a b: ~a~%" a b)
24
25  (set! counter (1+ counter))
26  (if (> counter 4)
27   (return)
28   (+ (apply + a) (apply + b))))
29
30 (rpc-start)
31
32 (format #t "I'm master process. Received ~s ~%"
33   (rpc-stream-map sum-all stream-add-one stream-add-two))
34
35 (rpc-finalize)