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: [PATCHES] Keyword args for file openers; coding scan off by default
Date: Sun, 07 Apr 2013 15:24:04 +0200	[thread overview]
Message-ID: <87d2u6v5hn.fsf@gnu.org> (raw)
In-Reply-To: 878v4uu92d.fsf@tines.lan

Mark H Weaver <mhw@netris.org> skribis:

> From 951b9d224d84bfec271b51615bc095013d153694 Mon Sep 17 00:00:00 2001
> From: Mark H Weaver <mhw@netris.org>
> Date: Sat, 6 Apr 2013 23:19:55 -0400
> Subject: [PATCH 3/3] Add keyword arguments to file opening procedures.
>
> * libguile/fports.c (scm_open_file_with_encoding): New API function,
>   containing the code previously found in 'scm_open_file', but modified
>   to accept the new 'guess_encoding' and 'encoding' arguments.
>
>   (scm_open_file): Now just a simple wrapper that calls
>   'scm_open_file_with_encoding'.
>
>   (scm_i_open_file): New implementation of 'open-file' that accepts
>   keyword arguments '#:guess-encoding' and '#:encoding', and calls
>   'scm_open_file_with_encoding'.
>
>   (scm_init_fports_keywords): New initialization function that gets
>   called after keywords are initialized.
>
> * libguile/fports.h (scm_open_file_with_encoding,
>   scm_init_fports_keywords): Add prototypes.
>
> * libguile/init.c (scm_i_init_guile): Call 'scm_init_fports_keywords'.
>
> * module/ice-9/boot-9.scm: Add enhanced versions of 'open-input-file',
>   'open-output-file', 'call-with-input-file', 'call-with-output-file',
>   'with-input-from-file', 'with-output-to-file', and
>   'with-error-to-file', that accept keyword arguments '#:binary',
>   '#:encoding', and (for input port constructors) '#:guess-encoding'.
>
> * doc/ref/api-io.texi (File Ports): Update documentation.
>
> * test-suite/tests/ports.test ("keyword arguments for file openers"):
>   Add tests.

Looks good.

Minor comments:

> +@deffn {Scheme Procedure} open-file filename mode @
> +                          [#:guess-encoding=#f] [#:encoding=#f]
> +@deffnx {C Function} scm_open_file_with_encoding @
> +                     (filename, mode, guess_encoding, encoding)
>  @deffnx {C Function} scm_open_file (filename, mode)
>  Open the file whose name is @var{filename}, and return a port
>  representing that file.  The attributes of the port are
> @@ -900,8 +903,17 @@ to the underlying @code{open} call.  Still, the flag is generally useful
>  because of its port encoding ramifications.
>  @end table
>  
> -If a file cannot be opened with the access
> -requested, @code{open-file} throws an exception.
> +Unless binary mode is requested, the character encoding of the new port
> +is determined as follows: First, if @var{guess-encoding} is true,
> +heuristics will be used to guess the encoding of the file.  If it is

“heuristics” is vague.  I’d prefer “the ‘file-encoding’ procedure is
called to check for Emacs-style coding declarations (@pxref{Character
Encoding of Source Files})”.  Should BOMs also be mentioned?

> +/* scm_open_file_with_encoding
>   * Return a new port open on a given file.
>   *
> + * Use heuristics to guess the encoding is GUESS_ENCODING
> + * is true, else use ENCODING if not false, else use the
> + * default port encoding.

Likewise.

And you’re welcome to remove the leading stars also.  :-)

> +SCM k_guess_encoding = SCM_UNDEFINED;
> +SCM k_encoding       = SCM_UNDEFINED;

Add ‘static’.

> +  scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0,
> +                                k_guess_encoding, &guess_encoding,
> +                                k_encoding, &encoding,
> +                                SCM_UNDEFINED);

Comes in handy.  ;-)

> +(define* (open-input-file
> +          str #:key (binary #f) (encoding #f) (guess-encoding #f))
> +  "Takes a string naming an existing file and returns an input port
> +capable of delivering characters from the file.  If the file
> +cannot be opened, an error is signalled."

It’s a detail, for these procedures, I would s/str/file/, and in
docstrings s/file STR/FILE/.

The test suite looks comprehensive, that’s great.

Thanks!

Ludo’.




  parent reply	other threads:[~2013-04-07 13:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07  6:52 [PATCHES] Keyword args for file openers; coding scan off by default Mark H Weaver
2013-04-07 13:00 ` Ludovic Courtès
2013-04-07 13:09 ` Ludovic Courtès
2013-04-07 13:24 ` Ludovic Courtès [this message]
2013-04-07 16:33   ` Mark H Weaver
2013-04-07 19:18     ` 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=87d2u6v5hn.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).