1 ;; Call with standard output
2 (print-int (current-output-port) 314159)
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"
12 (print-int (current-output-port) 314159)
16 ;; Redirection to a string or soft port won't work --
17 ;; we can only handle file ports.
20 (with-output-to-string
22 (print-int (current-output-port) 314159))))
24 (write args) (newline)))
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"
30 (display (read-int (current-input-port)))