Add `(srfi srfi-88)'.
authorLudovic Courtès <ludo@gnu.org>
Sat, 26 Apr 2008 17:34:37 +0000 (19:34 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sat, 26 Apr 2008 19:25:32 +0000 (21:25 +0200)
NEWS
doc/ref/ChangeLog
doc/ref/api-data.texi
doc/ref/srfi-modules.texi
srfi/ChangeLog
srfi/Makefile.am
srfi/srfi-88.scm [new file with mode: 0644]
test-suite/ChangeLog
test-suite/Makefile.am
test-suite/tests/srfi-88.test [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 8f01109f62928b12fb446f5ef471c8255156db63..9d4560d4acdfff550b1fb8c76e61ca38c910ce1c 100644 (file)
--- 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
index a5a9665336acc938bae5d15b27e6c36dc2520242..9aa75595aa68c57d0ff85879fca0b8803c285f80 100644 (file)
@@ -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?.
index 31c1c6b791d61454318d9f7287ccd77a21f5e4f4..2552b92f44f2dc8d7f52ae173e8b00348b1de16d 100755 (executable)
@@ -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
index 24809739d6db5271f6542f90a34e0a7069c8982b..d2bf6548bb7c1efc27e5ae6c778d8fee69c4616b 100644 (file)
@@ -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
 
index b409ecaee9fc129151472d48023bcb299576e044..cd696de630b84b2669d2ef5c2b91d731044f4bff 100644 (file)
@@ -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
index 7b78bbfd74ec249bffb89da3eb10d4635505e54e..c17fd98d6a106a8ae1ce2bfff64c38e3e84034a5 100644 (file)
@@ -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 (file)
index 0000000..ebde81d
--- /dev/null
@@ -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
index 210c802f73ad5fbc0ad6033aa92a407377da9345..9a2a63a97faf0aa09a1a5a67af22f5a518d16b92 100644 (file)
@@ -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
index 6b07eee5e1bf96d55dc3ba03b9ef49fa7528cfbd..f6ad699e5eadcf139289c572cfbf42db75119fcb 100644 (file)
@@ -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 (file)
index 0000000..63f40cc
--- /dev/null
@@ -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: