unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: %default-port-conversion-strategy and string ports
Date: Fri, 01 Jun 2012 18:34:04 +0200	[thread overview]
Message-ID: <87396fvvnn.fsf@gnu.org> (raw)
In-Reply-To: 87k3zrowj1.fsf@fencepost.gnu.org

Hi David,

Ports in Guile can be used to write characters, or bytes, or both.  In
particular, every port (including string ports, void ports, etc.) has an
“encoding”, which is actually only used for textual I/O.

Conversely, an R6RS port is either textual or binary, but not both.

IMO, one advantage of mixed text/binary ports is to allow things like this:

  scheme@(guile-user)> (define (string->utf16 s)
                         (let ((p (with-fluids ((%default-port-encoding "UTF-16BE"))
                                    (open-input-string s))))
                           (get-bytevector-all p)))
  scheme@(guile-user)> (string->utf16 "hello")
  $4 = #vu8(0 104 0 101 0 108 0 108 0 111)
  scheme@(guile-user)> (use-modules(rnrs bytevectors))
  scheme@(guile-user)> (utf16->string $4)
  $5 = "hello"

Thanks,
Ludo’.




  reply	other threads:[~2012-06-01 16:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 23:04 %default-port-conversion-strategy and string ports Ludovic Courtès
2012-05-30 23:48 ` Mike Gran
2012-05-31  5:09 ` David Kastrup
2012-05-31 14:05   ` Ludovic Courtès
2012-05-31 14:48     ` David Kastrup
2012-05-31 21:25     ` Mark H Weaver
2012-06-01 15:38       ` Ludovic Courtès
2012-06-01 15:57         ` David Kastrup
2012-06-01 16:34           ` Ludovic Courtès [this message]
2012-06-01 22:40             ` Mark H Weaver
2012-06-02 12:52               ` Ludovic Courtès
2012-06-02 14:55                 ` David Kastrup
2012-06-03 14:47                   ` Daniel Krueger
2012-06-03 22:22                     ` Separate textual/binary ports vs. mixed ports Ludovic Courtès
2012-06-05  9:31                       ` Daniel Krueger
2012-06-05 11:57                         ` Noah Lavine
2012-06-05 12:47                           ` Ludovic Courtès
2012-06-05 12:45                         ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87396fvvnn.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).