unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Implement SRFI 28
@ 2014-11-30 10:35 Chris K. Jester-Young
  2014-12-01 18:52 ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Chris K. Jester-Young @ 2014-11-30 10:35 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 158 bytes --]

Hi there,

Here's a simple implementation of SRFI 28, which I think would be useful
to provide in-tree for portability. Feedback welcome. :-)

Cheers,
Chris.

[-- Attachment #2: 0001-Implement-SRFI-28.patch --]
[-- Type: text/x-diff, Size: 4103 bytes --]

From b13b3cc1e362775ee06c446460d0926a8d67b569 Mon Sep 17 00:00:00 2001
From: Chris Jester-Young <cky944@gmail.com>
Date: Sun, 30 Nov 2014 05:20:54 -0500
Subject: [PATCH] Implement SRFI 28.

* module/srfi/srfi-28.scm: New module.
* module/Makefile.am: Build the (srfi srfi-28) module.
* doc/ref/srfi-modules.texi: Add documentation for (srfi srfi-28).
---
 doc/ref/srfi-modules.texi | 37 +++++++++++++++++++++++++++++++++++++
 module/Makefile.am        |  1 +
 module/srfi/srfi-28.scm   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 module/srfi/srfi-28.scm

diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 2cf9fd1..95a795d 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -38,6 +38,7 @@ get the relevant SRFI documents from the SRFI home page
 * SRFI-23::                     Error reporting
 * SRFI-26::                     Specializing parameters
 * SRFI-27::                     Sources of Random Bits
+* SRFI-28::                     Basic format strings.
 * SRFI-30::                     Nested multi-line block comments
 * SRFI-31::                     A special form `rec' for recursive evaluation
 * SRFI-34::                     Exception handling.
@@ -3276,6 +3277,42 @@ reasonably small value (related to the width of the mantissa of an
 efficient number format).
 @end defun
 
+@node SRFI-28
+@subsection SRFI-28 - Basic Format Strings
+@cindex SRFI-28
+
+SRFI-28 provides a basic @code{format} function that provides only the
+@code{~a}, @code{~s}, @code{~%}, and @code{~~} format specifiers. You
+can import this function by using:
+
+@lisp
+(use-modules (srfi srfi-28))
+@end lisp
+
+@defun format message arg @dots{}
+Returns a formatted message, using @var{message} as the format string,
+which can contain the following format specifiers:
+
+@table @code
+@item ~a
+Insert the textual representation of the next @var{arg}, as if printed
+by @code{display}.
+
+@item ~s
+Insert the textual representation of the next @var{arg}, as if printed
+by @code{write}.
+
+@item ~%
+Insert a newline.
+
+@item ~~
+Insert a tilde.
+@end table
+
+This function is the same as calling @code{simple-format} (@pxref{Writing})
+with @code{#f} as the destination.
+@end defun
+
 @node SRFI-30
 @subsection SRFI-30 - Nested Multi-line Comments
 @cindex SRFI-30
diff --git a/module/Makefile.am b/module/Makefile.am
index a9aaa76..7e96de7 100644
--- a/module/Makefile.am
+++ b/module/Makefile.am
@@ -278,6 +278,7 @@ SRFI_SOURCES = \
   srfi/srfi-19.scm \
   srfi/srfi-26.scm \
   srfi/srfi-27.scm \
+  srfi/srfi-28.scm \
   srfi/srfi-31.scm \
   srfi/srfi-34.scm \
   srfi/srfi-35.scm \
diff --git a/module/srfi/srfi-28.scm b/module/srfi/srfi-28.scm
new file mode 100644
index 0000000..7fc73eb
--- /dev/null
+++ b/module/srfi/srfi-28.scm
@@ -0,0 +1,34 @@
+;;; srfi-28.scm --- Basic Format Strings
+
+;; Copyright (C) 2014 Free Software Foundation, Inc.
+;;
+;; This library is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Lesser General Public
+;; License as published by the Free Software Foundation; either
+;; version 3 of the License, or (at your option) any later version.
+;;
+;; This library is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; Lesser General Public License for more details.
+;;
+;; You should have received a copy of the GNU Lesser General Public
+;; License along with this library; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+;;; Commentary:
+
+;; This module provides a wrapper for simple-format that always outputs
+;; to a string.
+;;
+;; This module is documented in the Guile Reference Manual.
+
+;;; Code:
+
+(define-module (srfi srfi-28)
+  #:replace (format))
+
+(define (format message . args)
+  (apply simple-format #f message args))
+
+(cond-expand-provide (current-module) '(srfi-28))
-- 
1.9.3 (Apple Git-50)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Implement SRFI 28
  2014-11-30 10:35 [PATCH] Implement SRFI 28 Chris K. Jester-Young
@ 2014-12-01 18:52 ` Mark H Weaver
  2014-12-02  3:25   ` Chris K. Jester-Young
  0 siblings, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2014-12-01 18:52 UTC (permalink / raw)
  To: guile-devel

Hi Chris,

"Chris K. Jester-Young" <cky944@gmail.com> writes:
> Here's a simple implementation of SRFI 28, which I think would be useful
> to provide in-tree for portability. Feedback welcome. :-)

Sounds good, thanks!  See below for comments.

> From b13b3cc1e362775ee06c446460d0926a8d67b569 Mon Sep 17 00:00:00 2001
> From: Chris Jester-Young <cky944@gmail.com>
> Date: Sun, 30 Nov 2014 05:20:54 -0500
> Subject: [PATCH] Implement SRFI 28.

Please add "Basic Format Strings" to the summary line here.

> * module/srfi/srfi-28.scm: New module.
> * module/Makefile.am: Build the (srfi srfi-28) module.
> * doc/ref/srfi-modules.texi: Add documentation for (srfi srfi-28).

These last two lines should include the variable and node names,
respectively, like this:

* module/Makefile.am (SRFI_SOURCES): Add srfi/srfi-28.scm.
* doc/ref/srfi-modules.texi (SRFI-28): New node.

> ---
>  doc/ref/srfi-modules.texi | 37 +++++++++++++++++++++++++++++++++++++
>  module/Makefile.am        |  1 +
>  module/srfi/srfi-28.scm   | 34 ++++++++++++++++++++++++++++++++++
>  3 files changed, 72 insertions(+)
>  create mode 100644 module/srfi/srfi-28.scm
>
> diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
> index 2cf9fd1..95a795d 100644
> --- a/doc/ref/srfi-modules.texi
> +++ b/doc/ref/srfi-modules.texi
> @@ -38,6 +38,7 @@ get the relevant SRFI documents from the SRFI home page
>  * SRFI-23::                     Error reporting
>  * SRFI-26::                     Specializing parameters
>  * SRFI-27::                     Sources of Random Bits
> +* SRFI-28::                     Basic format strings.
>  * SRFI-30::                     Nested multi-line block comments
>  * SRFI-31::                     A special form `rec' for recursive evaluation
>  * SRFI-34::                     Exception handling.
> @@ -3276,6 +3277,42 @@ reasonably small value (related to the width of the mantissa of an
>  efficient number format).
>  @end defun
>  
> +@node SRFI-28
> +@subsection SRFI-28 - Basic Format Strings
> +@cindex SRFI-28
> +
> +SRFI-28 provides a basic @code{format} function that provides only the
> +@code{~a}, @code{~s}, @code{~%}, and @code{~~} format specifiers. You
> +can import this function by using:

The Scheme standards call them "procedures" not "functions", and it
would be good to follow this convention.  Also, please put two spaces
between sentences.

> +
> +@lisp
> +(use-modules (srfi srfi-28))
> +@end lisp
> +
> +@defun format message arg @dots{}

Please use "@deffn {Scheme Procedure}" instead of "@defun".  I can see
that @defun is used about 8% of the time, but it would be good not to
add more.

> +Returns a formatted message, using @var{message} as the format string,
> +which can contain the following format specifiers:
> +
> +@table @code
> +@item ~a
> +Insert the textual representation of the next @var{arg}, as if printed
> +by @code{display}.
> +
> +@item ~s
> +Insert the textual representation of the next @var{arg}, as if printed
> +by @code{write}.
> +
> +@item ~%
> +Insert a newline.
> +
> +@item ~~
> +Insert a tilde.
> +@end table
> +
> +This function is the same as calling @code{simple-format} (@pxref{Writing})
> +with @code{#f} as the destination.
> +@end defun

function --> procedure and defun --> deffn.

The rest looks good to me.  Can you post an updated patch?

     Thanks!
       Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Implement SRFI 28
  2014-12-01 18:52 ` Mark H Weaver
@ 2014-12-02  3:25   ` Chris K. Jester-Young
  2014-12-02 17:35     ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Chris K. Jester-Young @ 2014-12-02  3:25 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

Hi Mark,

Thanks for your review! I've implemented all your review comments, and
have attached a new patch.

On Mon, Dec 01, 2014 at 01:52:08PM -0500, Mark H Weaver wrote:
>                                           Also, please put two spaces
> between sentences.

I sidestepped this by putting the new sentence on a new line. This is
also what I do with all the manpages I write. :-D

Cheers,
Chris.

[-- Attachment #2: 0001-Implement-SRFI-28-Basic-Format-Strings.patch --]
[-- Type: text/x-diff, Size: 4133 bytes --]

From 34cfbd817aecc119fd6bbc9925a6ecbace3961bc Mon Sep 17 00:00:00 2001
From: Chris Jester-Young <cky944@gmail.com>
Date: Sun, 30 Nov 2014 05:20:54 -0500
Subject: [PATCH] Implement SRFI 28: Basic Format Strings.

* module/srfi/srfi-28.scm: New module.
* module/Makefile.am (SRFI_SOURCES): Add srfi/srfi-28.scm.
* doc/ref/srfi-modules.texi (SRFI-28): New node.
---
 doc/ref/srfi-modules.texi | 37 +++++++++++++++++++++++++++++++++++++
 module/Makefile.am        |  1 +
 module/srfi/srfi-28.scm   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 module/srfi/srfi-28.scm

diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 2cf9fd1..d8ed8e1 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -38,6 +38,7 @@ get the relevant SRFI documents from the SRFI home page
 * SRFI-23::                     Error reporting
 * SRFI-26::                     Specializing parameters
 * SRFI-27::                     Sources of Random Bits
+* SRFI-28::                     Basic format strings.
 * SRFI-30::                     Nested multi-line block comments
 * SRFI-31::                     A special form `rec' for recursive evaluation
 * SRFI-34::                     Exception handling.
@@ -3276,6 +3277,42 @@ reasonably small value (related to the width of the mantissa of an
 efficient number format).
 @end defun
 
+@node SRFI-28
+@subsection SRFI-28 - Basic Format Strings
+@cindex SRFI-28
+
+SRFI-28 provides a basic @code{format} procedure that provides only
+the @code{~a}, @code{~s}, @code{~%}, and @code{~~} format specifiers.
+You can import this procedure by using:
+
+@lisp
+(use-modules (srfi srfi-28))
+@end lisp
+
+@deffn {Scheme Procedure} format message arg @dots{}
+Returns a formatted message, using @var{message} as the format string,
+which can contain the following format specifiers:
+
+@table @code
+@item ~a
+Insert the textual representation of the next @var{arg}, as if printed
+by @code{display}.
+
+@item ~s
+Insert the textual representation of the next @var{arg}, as if printed
+by @code{write}.
+
+@item ~%
+Insert a newline.
+
+@item ~~
+Insert a tilde.
+@end table
+
+This procedure is the same as calling @code{simple-format} (@pxref{Writing})
+with @code{#f} as the destination.
+@end deffn
+
 @node SRFI-30
 @subsection SRFI-30 - Nested Multi-line Comments
 @cindex SRFI-30
diff --git a/module/Makefile.am b/module/Makefile.am
index a9aaa76..7e96de7 100644
--- a/module/Makefile.am
+++ b/module/Makefile.am
@@ -278,6 +278,7 @@ SRFI_SOURCES = \
   srfi/srfi-19.scm \
   srfi/srfi-26.scm \
   srfi/srfi-27.scm \
+  srfi/srfi-28.scm \
   srfi/srfi-31.scm \
   srfi/srfi-34.scm \
   srfi/srfi-35.scm \
diff --git a/module/srfi/srfi-28.scm b/module/srfi/srfi-28.scm
new file mode 100644
index 0000000..7fc73eb
--- /dev/null
+++ b/module/srfi/srfi-28.scm
@@ -0,0 +1,34 @@
+;;; srfi-28.scm --- Basic Format Strings
+
+;; Copyright (C) 2014 Free Software Foundation, Inc.
+;;
+;; This library is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Lesser General Public
+;; License as published by the Free Software Foundation; either
+;; version 3 of the License, or (at your option) any later version.
+;;
+;; This library is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; Lesser General Public License for more details.
+;;
+;; You should have received a copy of the GNU Lesser General Public
+;; License along with this library; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+;;; Commentary:
+
+;; This module provides a wrapper for simple-format that always outputs
+;; to a string.
+;;
+;; This module is documented in the Guile Reference Manual.
+
+;;; Code:
+
+(define-module (srfi srfi-28)
+  #:replace (format))
+
+(define (format message . args)
+  (apply simple-format #f message args))
+
+(cond-expand-provide (current-module) '(srfi-28))
-- 
1.9.3 (Apple Git-50)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Implement SRFI 28
  2014-12-02  3:25   ` Chris K. Jester-Young
@ 2014-12-02 17:35     ` Mark H Weaver
  0 siblings, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2014-12-02 17:35 UTC (permalink / raw)
  To: guile-devel

"Chris K. Jester-Young" <cky944@gmail.com> writes:
> Thanks for your review! I've implemented all your review comments, and
> have attached a new patch.

Pushed to stable-2.0, thanks!

It would be good to enhance the 'format-analysis' warning pass in
(language tree-il analyze) to handle SRFI-28 format.  Any volunteers?

     Thanks,
       Mark



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-12-02 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-30 10:35 [PATCH] Implement SRFI 28 Chris K. Jester-Young
2014-12-01 18:52 ` Mark H Weaver
2014-12-02  3:25   ` Chris K. Jester-Young
2014-12-02 17:35     ` Mark H Weaver

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).