import source from 1.3.40
[external/swig.git] / Examples / guile / port / port.scm
1 ;; Call with standard output
2 (print-int (current-output-port) 314159)
3
4 ;; Redirection to a file. Note that the port is automatically flushed
5 ;; (via force-output) before calling the C function, and that the C
6 ;; function gets a temporary "FILE" stream, which is closed after the
7 ;; call. So you can simply mix Scheme and C output.
8 (with-output-to-file "test.out"
9   (lambda ()
10     (display 4711)
11     (newline)
12     (print-int (current-output-port) 314159)
13     (display 815)
14     (newline)))
15
16 ;; Redirection to a string or soft port won't work --
17 ;; we can only handle file ports.
18 (catch #t
19        (lambda ()
20          (with-output-to-string
21            (lambda ()
22              (print-int (current-output-port) 314159))))
23        (lambda args
24          (write args) (newline)))
25
26 ;; Read from a file port. Note that it is a bad idea to mix Scheme and
27 ;; C input because of buffering.
28 (with-input-from-file "test.out"
29   (lambda ()
30     (display (read-int (current-input-port)))
31     (newline)))
32