diff --git a/NEWS b/NEWS index 8f01109f6..9d4560d4a 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 a5a966533..9aa75595a 100644 --- a/doc/ref/ChangeLog +++ b/doc/ref/ChangeLog @@ -1,3 +1,9 @@ +2008-04-26 Ludovic Courtès + + * srfi-modules.texi (SRFI-88): New section. + * api-data.texi (Keyword Read Syntax): Add reference to + `SRFI-88'. + 2008-04-17 Neil Jerram * posix.texi (File System): New doc for file-exists?. diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index 31c1c6b79..2552b92f4 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 24809739d..d2bf6548b 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 b409ecaee..cd696de63 100644 --- a/srfi/ChangeLog +++ b/srfi/ChangeLog @@ -1,3 +1,8 @@ +2008-04-26 Ludovic Courtès + + * Makefile.am (srfi_DATA): Add `srfi-88.scm'. + * srfi-88.scm: New file. + 2008-03-12 Ludovic Courtès * srfi-37.scm (args-fold)[short-option]: Set ARGS to `(cdr diff --git a/srfi/Makefile.am b/srfi/Makefile.am index 7b78bbfd7..c17fd98d6 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 000000000..ebde81d0b --- /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 + +;;; 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)) + + +(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 210c802f7..9a2a63a97 100644 --- a/test-suite/ChangeLog +++ b/test-suite/ChangeLog @@ -1,3 +1,8 @@ +2008-04-26 Ludovic Courtès + + * Makefile.am (SCM_TESTS): Add `tests/srfi-88.test'. + * tests/srfi-88.test: New file. + 2008-04-15 Ludovic Courtès * tests/reader.test (read-options)[prefix non-keywords, postfix diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 6b07eee5e..f6ad699e5 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 000000000..63f40cc40 --- /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 +;;;; +;;;; 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)) + + +;; 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: