guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SRFI-88-style keywords


From: Ludovic Courtès
Subject: Re: SRFI-88-style keywords
Date: Sat, 26 Apr 2008 21:35:00 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Hi,

FYI, I added this tiny SRFI-88 module.

Thanks,
Ludovic.

>From efbc70de566adfa7f8863bcc8bf93f79b5d254e7 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
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  <address@hidden>
+
+       * srfi-modules.texi (SRFI-88): New section.
+       * api-data.texi (Keyword Read Syntax): Add reference to
+       `SRFI-88'.
+
 2008-04-17  Neil Jerram  <address@hidden>
 
        * 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.
address@hidden Copyright (C)  1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 
2007
address@hidden 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}.
 
address@hidden SRFI-88
address@hidden SRFI-88 Keyword Objects
address@hidden SRFI-88
address@hidden keyword objects
+
address@hidden://srfi.schemers.org/srfi/srfi-88.html, SRFI-88} provides
address@hidden objects}, which are equivalent to Guile's keywords
+(@pxref{Keywords}).  SRFI-88 keywords can be entered using the
address@hidden keyword syntax}, which consists of an identifier followed
+by @code{:} (@pxref{Reader options, @code{postfix} keyword syntax}).
+SRFI-88 can be made available with:
+
address@hidden
+(use-modules (srfi srfi-88))
address@hidden example
+
+Doing so installs the right reader option for keyword syntax, using
address@hidden(read-set! keywords 'postfix)}.  It also provides the procedures
+described below.
+
address@hidden {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,
address@hidden).
+
address@hidden
+(keyword? foo:)         @result{} #t
+(keyword? 'foo:)        @result{} #t
+(keyword? "foo")        @result{} #f
address@hidden example
address@hidden deffn
+
address@hidden {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
address@hidden
+
address@hidden
+(keyword->string foo:)  @result{} "foo"
address@hidden example
address@hidden deffn
+
address@hidden {Scheme Procedure} string->keyword str
+Return the keyword object whose name is @var{str}.
+
address@hidden
+(keyword->string (string->keyword "a b c"))     @result{} "a b c"
address@hidden example
address@hidden 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  <address@hidden>
+
+       * Makefile.am (srfi_DATA): Add `srfi-88.scm'.
+       * srfi-88.scm: New file.
+
 2008-03-12  Ludovic Courtès  <address@hidden>
 
        * 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 <address@hidden>
+
+;;; 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 210c802..9a2a63a 100644
--- a/test-suite/ChangeLog
+++ b/test-suite/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-26  Ludovic Courtès  <address@hidden>
+
+       * Makefile.am (SCM_TESTS): Add `tests/srfi-88.test'.
+       * tests/srfi-88.test: New file.
+
 2008-04-15  Ludovic Courtès  <address@hidden>
 
        * 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 <address@hidden>
+;;;;
+;;;;   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:
-- 
1.5.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]