Guile port example fix for Guile 2.0

Rewinding the file before passing it to C fixed the problem of not being
able to read the file contents.

Also explain the error about writing to a string.
This commit is contained in:
William S Fulton 2013-05-23 23:24:19 +01:00
commit 8700e79b3e

View file

@ -21,14 +21,15 @@
(lambda ()
(print-int (current-output-port) 314159))))
(lambda args
(display "Attempting to write to a string or soft port will result in this error:")
(display "Below shows that attempting to write to a string or soft port will result in a wrong-type-error...")
(newline)
(write args) (newline)))
;; Read from a file port. Note that it is a bad idea to mix Scheme and
;; C input because of buffering.
;; C input because of buffering, hence the call to seek to rewind the file.
(with-input-from-file "test.out"
(lambda ()
(seek (current-input-port) 0 SEEK_SET)
(display (read-int (current-input-port)))
(newline)))