On Fri 04 Mar 2016 04:09, Zefram <zef...@fysh.org> writes: > The documentation for drain-input says that it returns a string of > characters, implying that the result is equivalent to what you'd get > from calling read-char some number of times. In fact it differs in a > significant respect: whereas read-char decodes input octets according to > the port's selected encoding, drain-input ignores the selected encoding > and always decodes according to ISO-8859-1 (thus preserving the octet > values in character form). > > $ echo -n $'\1a\2b\3c' | guile-2.0 -c '(set-port-encoding! > (current-input-port) "UCS-2BE") (write (port-encoding > (current-input-port))) (newline) (write (map char->integer (let r ((l > '\''())) (let ((c (read-char (current-input-port)))) (if (eof-object? > c) (reverse l) (r (cons c l))))))) (newline)' > "UCS-2BE" > (353 610 867) > $ echo -n $'\1a\2b\3c' | guile-2.0 -c '(set-port-encoding! > (current-input-port) "UCS-2BE") (write (port-encoding > (current-input-port))) (newline) (peek-char (current-input-port)) > (write (map char->integer (string->list (drain-input > (current-input-port))))) (newline)' > "UCS-2BE" > (1 97 2 98 3 99)
Thanks for the test case! FWIW, this is fixed in Guile 2.1.3. I am not sure what we should do about Guile 2.0. I guess we should make it do the documented thing though! Andy