unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* SRFI-88-style keywords
@ 2007-11-03  0:14 Julian Graham
  2007-11-03 14:37 ` Ludovic Courtès
  2008-04-15 18:08 ` Ludovic Courtès
  0 siblings, 2 replies; 8+ messages in thread
From: Julian Graham @ 2007-11-03  0:14 UTC (permalink / raw)
  To: Guile Development

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

Hi Guilers,

I was looking at some SRFIs recently (specifically SRFIs 88, 89, and
90), and I noticed that Guile could support all three of them pretty
easily if the reader allowed self-quoting keywords in which the colon
comes at the end, a la SRFI-88.  The default reader behavior is to
only parse tokens as keywords if they begin with #: (e.g., #:foo), but
you can modify this behavior by setting the reader option (keywords
'prefix), which gets you keywords that start with just the colon
(e.g., :foo).  What if we added another reader option, say, (keywords
'postfix), which would recognize SRFI-88-style keywords?

I've attached a (slightly clumsy) patch against HEAD that adds this
functionality to read.c.  I know this is unsolicited, but I think it'd
be fairly useful in terms of compatibility.


Regards,
Julian

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: postfix-keywords.HEAD.patch --]
[-- Type: text/x-patch; name=postfix-keywords.HEAD.patch, Size: 1990 bytes --]

Index: read.c
===================================================================
RCS file: /sources/guile/guile/guile-core/libguile/read.c,v
retrieving revision 1.128
diff -a -u -r1.128 read.c
--- read.c	17 Oct 2007 21:56:10 -0000	1.128
+++ read.c	2 Nov 2007 23:54:18 -0000
@@ -53,6 +53,7 @@
 
 SCM_GLOBAL_SYMBOL (scm_sym_dot, ".");
 SCM_SYMBOL (scm_keyword_prefix, "prefix");
+SCM_SYMBOL (scm_keyword_postfix, "postfix");
 
 scm_t_option scm_read_opts[] = {
   { SCM_OPTION_BOOLEAN, "copy", 0,
@@ -62,7 +63,7 @@
   { SCM_OPTION_BOOLEAN, "case-insensitive", 0,
     "Convert symbols to lower case."},
   { SCM_OPTION_SCM, "keywords", SCM_UNPACK (SCM_BOOL_F),
-    "Style of keyword recognition: #f or 'prefix."},
+    "Style of keyword recognition: #f, 'prefix, or 'postfix."},
 #if SCM_ENABLE_ELISP
   { SCM_OPTION_BOOLEAN, "elisp-vectors", 0,
     "Support Elisp vector syntax, namely `[...]'."},
@@ -532,6 +533,8 @@
 {
   SCM result, str = SCM_EOL;
   int overflow = 0;
+  int postfix = scm_is_eq (SCM_PACK (SCM_KEYWORD_STYLE), scm_keyword_postfix);
+		  
   char buffer[READER_BUFFER_SIZE];
   size_t read = 0;
 
@@ -549,12 +552,26 @@
     {
       str = scm_string_concatenate (scm_reverse_x (str, SCM_EOL));
       result = scm_string_to_symbol (str);
+      
+      if (postfix)
+	{
+	  size_t l = scm_c_string_length (str) - 1;
+	  if (l && scm_is_true (scm_char_eq_p (scm_c_string_ref (str, l),
+					       SCM_MAKE_CHAR (':'))))
+	    result = scm_from_locale_keywordn (scm_i_string_chars (str), l);
+	}
     }
   else
+    {
+
     /* For symbols smaller than `sizeof (buffer)', we don't need to recur to
        Scheme strings.  Therefore, we only create one Scheme object (a
        symbol) per symbol read.  */
-    result = scm_from_locale_symboln (buffer, read);
+      if (postfix && read > 1 && buffer[read - 1] == ':')
+	result = scm_from_locale_keywordn (buffer, read - 1);
+      else 
+	result = scm_from_locale_symboln (buffer, read);
+    }
 
   return result;
 }

[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel

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

* Re: SRFI-88-style keywords
  2007-11-03  0:14 SRFI-88-style keywords Julian Graham
@ 2007-11-03 14:37 ` Ludovic Courtès
  2008-04-15 18:08 ` Ludovic Courtès
  1 sibling, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2007-11-03 14:37 UTC (permalink / raw)
  To: guile-devel

Hi,

"Julian Graham" <joolean@gmail.com> writes:

> I was looking at some SRFIs recently (specifically SRFIs 88, 89, and
> 90), and I noticed that Guile could support all three of them pretty
> easily if the reader allowed self-quoting keywords in which the colon
> comes at the end, a la SRFI-88.  The default reader behavior is to
> only parse tokens as keywords if they begin with #: (e.g., #:foo), but
> you can modify this behavior by setting the reader option (keywords
> 'prefix), which gets you keywords that start with just the colon
> (e.g., :foo).  What if we added another reader option, say, (keywords
> 'postfix), which would recognize SRFI-88-style keywords?

Looks like a good idea.

I tend to think we would not add it in 1.8, or at least not in 1.8.4, so
that the reader can stabilize before we break it again.  :-)

Thanks,
Ludovic.



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


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

* Re: SRFI-88-style keywords
  2007-11-03  0:14 SRFI-88-style keywords Julian Graham
  2007-11-03 14:37 ` Ludovic Courtès
@ 2008-04-15 18:08 ` Ludovic Courtès
  2008-04-15 18:30   ` Julian Graham
  2008-04-26 19:35   ` Ludovic Courtès
  1 sibling, 2 replies; 8+ messages in thread
From: Ludovic Courtès @ 2008-04-15 18:08 UTC (permalink / raw)
  To: guile-devel

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

Hi,

"Julian Graham" <joolean@gmail.com> writes:

> What if we added another reader option, say, (keywords 'postfix),
> which would recognize SRFI-88-style keywords?

I think now is a good time so I just committed the attached patch.

Now, we should do something about `cond-expand' and `require-extension'.
For the former, we should probably look at the current value of
`(read-options)', but that requires changing the implementation of
`cond-expand'.  For the latter, we can provide a dummy module that
modifies `read-options' and re-export the needed procedures.

Thoughts?

Thanks,
Ludovic.


[-- Attachment #2: The patch --]
[-- Type: text/x-patch, Size: 9129 bytes --]

From 75946eddfc4b086f59766ea1e207480261be0315 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Tue, 15 Apr 2008 19:52:43 +0200
Subject: [PATCH] Add support for SRFI-88-like postfix keyword read syntax.

---
 NEWS                         |    4 ++++
 doc/ref/ChangeLog            |    7 +++++++
 doc/ref/api-data.texi        |   22 ++++++++++++++++++++--
 doc/ref/api-options.texi     |    6 +++---
 libguile/ChangeLog           |    7 +++++++
 libguile/read.c              |   26 ++++++++++++++++++++------
 test-suite/ChangeLog         |    5 +++++
 test-suite/tests/reader.test |   16 +++++++++++++++-
 8 files changed, 81 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index 6d889d3..02b90e6 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,10 @@ The new repository can be accessed using
 "git-clone git://git.sv.gnu.org/guile.git", or can be browsed on-line at
 http://git.sv.gnu.org/gitweb/?p=guile.git .  See `README' for details.
 
+* New features (see the manual for details)
+
+** New `postfix' read option, for SRFI-88 keyword syntax
+
 * Bugs fixed
 
 ** `scm_add_slot ()' no longer segfaults (fixes bug #22369)
diff --git a/doc/ref/ChangeLog b/doc/ref/ChangeLog
index b41db5c..371cac3 100644
--- a/doc/ref/ChangeLog
+++ b/doc/ref/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-15  Ludovic Courtès  <ludo@gnu.org>
+
+	* api-data.texi (Keywords): Mention postfix syntax.
+	(Keyword Read Syntax): Document `postfix' read option.
+	* api-options.texi (Reader options): Update examples.
+	(Examples of option use): Likewise.
+
 2008-03-19  Neil Jerram  <neil@ossau.uklinux.net>
 
 	* api-debug.texi (Debugging Examples): New (from CVS HEAD).
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index f4549f6..31c1c6b 100755
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -4894,7 +4894,7 @@ makes them easy to type.
 
 Guile's keyword support conforms to R5RS, and adds a (switchable) read
 syntax extension to permit keywords to begin with @code{:} as well as
-@code{#:}.
+@code{#:}, or to end with @code{:}.
 
 @menu
 * Why Use Keywords?::           Motivation for keyword usage.
@@ -5039,9 +5039,17 @@ If the @code{keyword} read option is set to @code{'prefix}, Guile also
 recognizes the alternative read syntax @code{:NAME}.  Otherwise, tokens
 of the form @code{:NAME} are read as symbols, as required by R5RS.
 
+@cindex SRFI-88 keyword syntax
+
+If the @code{keyword} read option is set to @code{'postfix}, Guile
+recognizes the @uref{http://srfi.schemers.org/srfi-88/srfi-88.html,
+SRFI-88 read syntax} @code{NAME:}.  Otherwise, tokens of this form are
+read as symbols.
+
 To enable and disable the alternative non-R5RS keyword syntax, you use
 the @code{read-set!} procedure documented in @ref{User level options
-interfaces} and @ref{Reader options}.
+interfaces} and @ref{Reader options}.  Note that the @code{prefix} and
+@code{postfix} syntax are mutually exclusive.
 
 @smalllisp
 (read-set! keywords 'prefix)
@@ -5054,6 +5062,16 @@ interfaces} and @ref{Reader options}.
 @result{}
 #:type
 
+(read-set! keywords 'postfix)
+
+type:
+@result{}
+#:type
+
+:type
+@result{}
+:type
+
 (read-set! keywords #f)
 
 #:type
diff --git a/doc/ref/api-options.texi b/doc/ref/api-options.texi
index ed1c42d..0805108 100644
--- a/doc/ref/api-options.texi
+++ b/doc/ref/api-options.texi
@@ -1,6 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Guile Reference Manual.
-@c Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+@c Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008
 @c   Free Software Foundation, Inc.
 @c See the file guile.texi for copying conditions.
 
@@ -491,7 +491,7 @@ Here is the list of reader options generated by typing
 values.
 
 @smalllisp
-keywords         #f      Style of keyword recognition: #f or 'prefix
+keywords         #f      Style of keyword recognition: #f, 'prefix or 'postfix
 case-insensitive no      Convert symbols to lower case.
 positions        yes     Record positions of source code expressions.
 copy             no      Copy source code expressions.
@@ -715,7 +715,7 @@ ABORT: (misc-error)
 
 Type "(backtrace)" to get more information.
 guile> (read-options 'help)
-keywords	#f	Style of keyword recognition: #f or 'prefix
+keywords	#f	Style of keyword recognition: #f, 'prefix or 'postfix
 case-insensitive	no	Convert symbols to lower case.
 positions	yes	Record positions of source code expressions.
 copy		no	Copy source code expressions.
diff --git a/libguile/ChangeLog b/libguile/ChangeLog
index 93453f4..5692927 100644
--- a/libguile/ChangeLog
+++ b/libguile/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-15  Ludovic Courtès  <ludo@gnu.org>
+	    Julian Graham  <joolean@gmail.com>
+
+	* read.c (scm_keyword_postfix): New.
+	(scm_read_opts): Update docstring for `keywords'.
+	(scm_read_mixed_case_symbol): Add support for postfix keywords.
+
 2008-04-13  Ludovic Courtès  <ludo@gnu.org>
 
 	* inline.h (SCM_C_USE_EXTERN_INLINE): New macro.  Use it to make
diff --git a/libguile/read.c b/libguile/read.c
index 8290f19..8bc1dff 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -54,6 +54,7 @@
 
 SCM_GLOBAL_SYMBOL (scm_sym_dot, ".");
 SCM_SYMBOL (scm_keyword_prefix, "prefix");
+SCM_SYMBOL (scm_keyword_postfix, "postfix");
 
 scm_t_option scm_read_opts[] = {
   { SCM_OPTION_BOOLEAN, "copy", 0,
@@ -63,7 +64,7 @@ scm_t_option scm_read_opts[] = {
   { SCM_OPTION_BOOLEAN, "case-insensitive", 0,
     "Convert symbols to lower case."},
   { SCM_OPTION_SCM, "keywords", SCM_UNPACK (SCM_BOOL_F),
-    "Style of keyword recognition: #f or 'prefix."}
+    "Style of keyword recognition: #f, 'prefix or 'postfix."},
 #if SCM_ENABLE_ELISP
   ,
   { SCM_OPTION_BOOLEAN, "elisp-vectors", 0,
@@ -561,15 +562,19 @@ static SCM
 scm_read_mixed_case_symbol (int chr, SCM port)
 {
   SCM result, str = SCM_EOL;
-  int overflow = 0;
+  int overflow = 0, ends_with_colon = 0;
   char buffer[READER_BUFFER_SIZE];
   size_t read = 0;
+  int postfix = scm_is_eq (SCM_PACK (SCM_KEYWORD_STYLE), scm_keyword_postfix);
 
   scm_ungetc (chr, port);
   do
     {
       overflow = read_token (port, buffer, sizeof (buffer), &read);
 
+      if (read > 0)
+	ends_with_colon = (buffer[read - 1] == ':');
+
       if ((overflow) || (scm_is_pair (str)))
 	str = scm_cons (scm_from_locale_stringn (buffer, read), str);
     }
@@ -579,12 +584,21 @@ scm_read_mixed_case_symbol (int chr, SCM port)
     {
       str = scm_string_concatenate (scm_reverse_x (str, SCM_EOL));
       result = scm_string_to_symbol (str);
+
+      /* Per SRFI-88, `:' alone is an identifier, not a keyword.  */
+      if (postfix && ends_with_colon && (scm_c_string_length (result) > 1))
+	result = scm_symbol_to_keyword (result);
     }
   else
-    /* For symbols smaller than `sizeof (buffer)', we don't need to recur to
-       Scheme strings.  Therefore, we only create one Scheme object (a
-       symbol) per symbol read.  */
-    result = scm_from_locale_symboln (buffer, read);
+    {
+      /* For symbols smaller than `sizeof (buffer)', we don't need to recur
+	 to Scheme strings.  Therefore, we only create one Scheme object (a
+	 symbol) per symbol read.  */
+      if (postfix && ends_with_colon && (read > 1))
+	result = scm_from_locale_keywordn (buffer, read - 1);
+      else
+	result = scm_from_locale_symboln (buffer, read);
+    }
 
   return result;
 }
diff --git a/test-suite/ChangeLog b/test-suite/ChangeLog
index 518e53f..210c802 100644
--- a/test-suite/ChangeLog
+++ b/test-suite/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-15  Ludovic Courtès  <ludo@gnu.org>
+
+	* tests/reader.test (read-options)[prefix non-keywords, postfix
+	keywords, `:' is not a postfix keyword (per SRFI-88)]: New tests.
+
 2008-04-13  Ludovic Courtès  <ludo@gnu.org>
 
 	* tests/goops.test (defining classes)[interaction with
diff --git a/test-suite/tests/reader.test b/test-suite/tests/reader.test
index d6047a2..0b13cf1 100644
--- a/test-suite/tests/reader.test
+++ b/test-suite/tests/reader.test
@@ -1,6 +1,6 @@
 ;;;; reader.test --- Exercise the reader.               -*- Scheme -*-
 ;;;;
-;;;; Copyright (C) 1999, 2001, 2002, 2003, 2007 Free Software Foundation, Inc.
+;;;; Copyright (C) 1999, 2001, 2002, 2003, 2007, 2008 Free Software Foundation, Inc.
 ;;;; Jim Blandy <jimb@red-bean.com>
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
@@ -149,6 +149,20 @@
          (with-read-options '(keywords prefix case-insensitive)
            (lambda ()
              (read-string ":KeyWord")))))
+  (pass-if "prefix non-keywords"
+    (symbol? (with-read-options '(keywords prefix)
+               (lambda ()
+                 (read-string "srfi88-keyword:")))))
+  (pass-if "postfix keywords"
+    (eq? #:keyword
+         (with-read-options '(keywords postfix)
+           (lambda ()
+             (read-string "keyword:")))))
+  (pass-if "`:' is not a postfix keyword (per SRFI-88)"
+    (eq? ':
+         (with-read-options '(keywords postfix)
+           (lambda ()
+             (read-string ":")))))
   (pass-if "no positions"
     (let ((sexp (with-read-options '()
                   (lambda ()
-- 
1.5.5


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

* Re: SRFI-88-style keywords
  2008-04-15 18:08 ` Ludovic Courtès
@ 2008-04-15 18:30   ` Julian Graham
  2008-04-15 18:56     ` Ludovic Courtès
  2008-04-26 19:35   ` Ludovic Courtès
  1 sibling, 1 reply; 8+ messages in thread
From: Julian Graham @ 2008-04-15 18:30 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

>  I think now is a good time so I just committed the attached patch.

Yay!  Thanks, Ludovic.


>  Now, we should do something about `cond-expand' and `require-extension'.
>  For the former, we should probably look at the current value of
>  `(read-options)', but that requires changing the implementation of
>  `cond-expand'.  For the latter, we can provide a dummy module that
>  modifies `read-options' and re-export the needed procedures.
>
>  Thoughts?

Sorry, what's the context?  Is it that those functions read characters
independent of the default reader?




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

* Re: SRFI-88-style keywords
  2008-04-15 18:30   ` Julian Graham
@ 2008-04-15 18:56     ` Ludovic Courtès
  0 siblings, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2008-04-15 18:56 UTC (permalink / raw)
  To: guile-devel

Hi,

"Julian Graham" <joolean@gmail.com> writes:

>>  Now, we should do something about `cond-expand' and `require-extension'.
>>  For the former, we should probably look at the current value of
>>  `(read-options)', but that requires changing the implementation of
>>  `cond-expand'.  For the latter, we can provide a dummy module that
>>  modifies `read-options' and re-export the needed procedures.
>>
>>  Thoughts?
>
> Sorry, what's the context?  Is it that those functions read characters
> independent of the default reader?

We want `cond-expand' (SRFI-0) and `require-extension' (SRFI-55) to be
SRFI-88-aware if possible.  See what I mean?

Thanks,
Ludo'.





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

* Re: SRFI-88-style keywords
  2008-04-15 18:08 ` Ludovic Courtès
  2008-04-15 18:30   ` Julian Graham
@ 2008-04-26 19:35   ` Ludovic Courtès
  2008-04-27  5:31     ` Julian Graham
  1 sibling, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2008-04-26 19:35 UTC (permalink / raw)
  To: guile-devel

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

Hi,

FYI, I added this tiny SRFI-88 module.

Thanks,
Ludovic.


[-- Attachment #2: The patch --]
[-- Type: text/x-patch, Size: 11086 bytes --]

From efbc70de566adfa7f8863bcc8bf93f79b5d254e7 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Sat, 26 Apr 2008 19:34:37 +0200
Subject: [PATCH] Add `(srfi srfi-88)'.

---
 NEWS                          |    4 +++
 doc/ref/ChangeLog             |    6 ++++
 doc/ref/api-data.texi         |    5 +--
 doc/ref/srfi-modules.texi     |   53 ++++++++++++++++++++++++++++++++++++-
 srfi/ChangeLog                |    5 +++
 srfi/Makefile.am              |    5 ++-
 srfi/srfi-88.scm              |   50 ++++++++++++++++++++++++++++++++++
 test-suite/ChangeLog          |    5 +++
 test-suite/Makefile.am        |    3 +-
 test-suite/tests/srfi-88.test |   59 +++++++++++++++++++++++++++++++++++++++++
 10 files changed, 188 insertions(+), 7 deletions(-)
 create mode 100644 srfi/srfi-88.scm
 create mode 100644 test-suite/tests/srfi-88.test

diff --git a/NEWS b/NEWS
index 8f01109..9d4560d 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,10 @@ The new repository can be accessed using
 "git-clone git://git.sv.gnu.org/guile.git", or can be browsed on-line at
 http://git.sv.gnu.org/gitweb/?p=guile.git .  See `README' for details.
 
+* New modules (see the manual for details)
+
+** `(srfi srfi-88)'
+
 * New features (see the manual for details)
 
 ** New `postfix' read option, for SRFI-88 keyword syntax
diff --git a/doc/ref/ChangeLog b/doc/ref/ChangeLog
index a5a9665..9aa7559 100644
--- a/doc/ref/ChangeLog
+++ b/doc/ref/ChangeLog
@@ -1,3 +1,9 @@
+2008-04-26  Ludovic Courtès  <ludo@gnu.org>
+
+	* srfi-modules.texi (SRFI-88): New section.
+	* api-data.texi (Keyword Read Syntax): Add reference to
+	`SRFI-88'.
+
 2008-04-17  Neil Jerram  <neil@ossau.uklinux.net>
 
 	* posix.texi (File System): New doc for file-exists?.
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 31c1c6b..2552b92 100755
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -5042,9 +5042,8 @@ of the form @code{:NAME} are read as symbols, as required by R5RS.
 @cindex SRFI-88 keyword syntax
 
 If the @code{keyword} read option is set to @code{'postfix}, Guile
-recognizes the @uref{http://srfi.schemers.org/srfi-88/srfi-88.html,
-SRFI-88 read syntax} @code{NAME:}.  Otherwise, tokens of this form are
-read as symbols.
+recognizes the SRFI-88 read syntax @code{NAME:} (@pxref{SRFI-88}).
+Otherwise, tokens of this form are read as symbols.
 
 To enable and disable the alternative non-R5RS keyword syntax, you use
 the @code{read-set!} procedure documented in @ref{User level options
diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 2480973..d2bf654 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -1,6 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Guile Reference Manual.
-@c Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007
+@c Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008
 @c   Free Software Foundation, Inc.
 @c See the file guile.texi for copying conditions.
 
@@ -45,6 +45,7 @@ get the relevant SRFI documents from the SRFI home page
 * SRFI-60::                     Integers as bits.
 * SRFI-61::                     A more general `cond' clause
 * SRFI-69::                     Basic hash tables.
+* SRFI-88::                     Keyword objects.
 @end menu
 
 
@@ -3215,6 +3216,56 @@ Answer a hash value appropriate for equality predicate @code{equal?},
 @code{hash} is a backwards-compatible replacement for Guile's built-in
 @code{hash}.
 
+@node SRFI-88
+@subsection SRFI-88 Keyword Objects
+@cindex SRFI-88
+@cindex keyword objects
+
+@uref{http://srfi.schemers.org/srfi/srfi-88.html, SRFI-88} provides
+@dfn{keyword objects}, which are equivalent to Guile's keywords
+(@pxref{Keywords}).  SRFI-88 keywords can be entered using the
+@dfn{postfix keyword syntax}, which consists of an identifier followed
+by @code{:} (@pxref{Reader options, @code{postfix} keyword syntax}).
+SRFI-88 can be made available with:
+
+@example
+(use-modules (srfi srfi-88))
+@end example
+
+Doing so installs the right reader option for keyword syntax, using
+@code{(read-set! keywords 'postfix)}.  It also provides the procedures
+described below.
+
+@deffn {Scheme Procedure} keyword? obj
+Return @code{#t} if @var{obj} is a keyword.  This is the same procedure
+as the same-named built-in procedure (@pxref{Keyword Procedures,
+@code{keyword?}}).
+
+@example
+(keyword? foo:)         @result{} #t
+(keyword? 'foo:)        @result{} #t
+(keyword? "foo")        @result{} #f
+@end example
+@end deffn
+
+@deffn {Scheme Procedure} keyword->string kw
+Return the name of @var{kw} as a string, i.e., without the trailing
+colon.  The returned string may not be modified, e.g., with
+@code{string-set!}.
+
+@example
+(keyword->string foo:)  @result{} "foo"
+@end example
+@end deffn
+
+@deffn {Scheme Procedure} string->keyword str
+Return the keyword object whose name is @var{str}.
+
+@example
+(keyword->string (string->keyword "a b c"))     @result{} "a b c"
+@end example
+@end deffn
+
 
 @c srfi-modules.texi ends here
 
diff --git a/srfi/ChangeLog b/srfi/ChangeLog
index b409eca..cd696de 100644
--- a/srfi/ChangeLog
+++ b/srfi/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-26  Ludovic Courtès  <ludo@gnu.org>
+
+	* Makefile.am (srfi_DATA): Add `srfi-88.scm'.
+	* srfi-88.scm: New file.
+
 2008-03-12  Ludovic Courtès  <ludo@gnu.org>
 
 	* srfi-37.scm (args-fold)[short-option]: Set ARGS to `(cdr
diff --git a/srfi/Makefile.am b/srfi/Makefile.am
index 7b78bbf..c17fd98 100644
--- a/srfi/Makefile.am
+++ b/srfi/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with Automake to create Makefile.in
 ##
-##   Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+##   Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 ##
 ##   This file is part of GUILE.
 ##
@@ -78,7 +78,8 @@ srfi_DATA = srfi-1.scm \
             srfi-37.scm \
             srfi-39.scm \
             srfi-60.scm \
-	    srfi-69.scm
+	    srfi-69.scm \
+	    srfi-88.scm
 
 EXTRA_DIST = $(srfi_DATA) 
 TAGS_FILES = $(srfi_DATA)
diff --git a/srfi/srfi-88.scm b/srfi/srfi-88.scm
new file mode 100644
index 0000000..ebde81d
--- /dev/null
+++ b/srfi/srfi-88.scm
@@ -0,0 +1,50 @@
+;;; srfi-88.scm --- Keyword Objects
+
+;; Copyright (C) 2008 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 2.1 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
+
+;;; Author: Ludovic Courtès <ludo@gnu.org>
+
+;;; Commentary:
+
+;; This is a convenience module providing SRFI-88 "keyword object".  All it
+;; does is setup the right reader option and export keyword-related
+;; convenience procedures.
+
+;;; Code:
+
+(define-module (srfi srfi-88)
+  #:re-export (keyword?)
+  #:export (keyword->string string->keyword))
+
+(cond-expand-provide (current-module) '(srfi-88))
+
+\f
+(read-set! keywords 'postfix)
+
+(define (keyword->string k)
+  "Return the name of @var{k} as a string."
+  (symbol->string (keyword->symbol k)))
+
+(define (string->keyword s)
+  "Return the keyword object whose name is @var{s}."
+  (symbol->keyword (string->symbol s)))
+
+;;; Local Variables:
+;;; coding: latin-1
+;;; End:
+
+;;; srfi-88.scm ends here
diff --git a/test-suite/ChangeLog b/test-suite/ChangeLog
index 210c802..9a2a63a 100644
--- a/test-suite/ChangeLog
+++ b/test-suite/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-26  Ludovic Courtès  <ludo@gnu.org>
+
+	* Makefile.am (SCM_TESTS): Add `tests/srfi-88.test'.
+	* tests/srfi-88.test: New file.
+
 2008-04-15  Ludovic Courtès  <ludo@gnu.org>
 
 	* tests/reader.test (read-options)[prefix non-keywords, postfix
diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am
index 6b07eee..f6ad699 100644
--- a/test-suite/Makefile.am
+++ b/test-suite/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in.
 ##
-## Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Software Foundation, Inc.
+## Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Software Foundation, Inc.
 ##
 ## This file is part of GUILE.
 ##
@@ -80,6 +80,7 @@ SCM_TESTS = tests/alist.test			\
 	    tests/srfi-39.test			\
 	    tests/srfi-60.test			\
 	    tests/srfi-69.test			\
+	    tests/srfi-88.test			\
 	    tests/srfi-4.test			\
 	    tests/srfi-9.test			\
 	    tests/strings.test			\
diff --git a/test-suite/tests/srfi-88.test b/test-suite/tests/srfi-88.test
new file mode 100644
index 0000000..63f40cc
--- /dev/null
+++ b/test-suite/tests/srfi-88.test
@@ -0,0 +1,59 @@
+;;;; srfi-88.test --- Test suite for SRFI-88               -*- Scheme -*-
+;;;; Ludovic Courtès <ludo@gnu.org>
+;;;;
+;;;; 	Copyright (C) 2008 Free Software Foundation, Inc.
+;;;;
+;;;; This program is free software; you can redistribute it and/or modify
+;;;; it under the terms of the GNU General Public License as published by
+;;;; the Free Software Foundation; either version 2, or (at your option)
+;;;; any later version.
+;;;;
+;;;; This program 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 General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License
+;;;; along with this software; see the file COPYING.  If not, write to
+;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;;;; Boston, MA 02110-1301 USA
+
+(define-module (test-srfi-88)
+  :use-module (test-suite lib)
+  :use-module (srfi srfi-88))
+
+\f
+;; Most of the test cases are taken from SRFI-88.
+
+(with-test-prefix "srfi-88"
+
+  (pass-if "cond-expand"
+    (cond-expand (srfi-88 #t)
+                 (else    #f)))
+
+  (pass-if "keyword?"
+    (and (keyword? 'foo:)
+         (keyword? foo:)
+         (not (keyword? 'foo))
+         (not (keyword? ':))
+         (keyword? (car '(a: b:)))
+         (not (keyword? "bar"))))
+
+  (pass-if "keyword->string"
+    (and (string=? (keyword->string foo:) "foo")
+         (string=? "a b c"
+                   (keyword->string (string->keyword "a b c")))))
+
+  (pass-if "string->keyword"
+    (eq? (string->keyword "foo") foo:))
+
+  (pass-if "empty keyword"
+    ;; XXX: We don't currently support syntax of the form
+    ;; `#{extended symbol}#:'.
+    (string=? ""
+              (keyword->string (string->keyword "")))))
+
+
+;;; Local Variables:
+;;; coding: latin-1
+;;; End:
-- 
1.5.5


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

* Re: SRFI-88-style keywords
  2008-04-26 19:35   ` Ludovic Courtès
@ 2008-04-27  5:31     ` Julian Graham
  2008-04-27 11:22       ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Julian Graham @ 2008-04-27  5:31 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

Hey, cool -- this will be really handy.

I'll look at cond-expand and require-extension.  And unless anyone
objects, I'd like to take a stab at adding SRFI-89 and SRFI-90.


Regards,
Julian


On Sat, Apr 26, 2008 at 3:35 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> Hi,
>
>  FYI, I added this tiny SRFI-88 module.




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

* Re: SRFI-88-style keywords
  2008-04-27  5:31     ` Julian Graham
@ 2008-04-27 11:22       ` Ludovic Courtès
  0 siblings, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2008-04-27 11:22 UTC (permalink / raw)
  To: guile-devel

Hi,

"Julian Graham" <joolean@gmail.com> writes:

> I'll look at cond-expand and require-extension.

With that patch checked in, one can already do:

  (require-extension (srfi 88))

and then:

  (cond-expand (srfi-88 #t)
               (else    #f))
  |=
  #t

> And unless anyone objects, I'd like to take a stab at adding SRFI-89
> and SRFI-90.

Yes, that'd be nice!

Thanks,
Ludovic.





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

end of thread, other threads:[~2008-04-27 11:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-03  0:14 SRFI-88-style keywords Julian Graham
2007-11-03 14:37 ` Ludovic Courtès
2008-04-15 18:08 ` Ludovic Courtès
2008-04-15 18:30   ` Julian Graham
2008-04-15 18:56     ` Ludovic Courtès
2008-04-26 19:35   ` Ludovic Courtès
2008-04-27  5:31     ` Julian Graham
2008-04-27 11:22       ` Ludovic Courtès

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