diff options
Diffstat (limited to 'srfi')
-rw-r--r-- | srfi/ChangeLog | 12 | ||||
-rw-r--r-- | srfi/Makefile.am | 6 | ||||
-rw-r--r-- | srfi/srfi-10.scm | 85 | ||||
-rw-r--r-- | srfi/srfi-17.scm | 99 | ||||
-rw-r--r-- | srfi/srfi-9.scm | 4 |
5 files changed, 203 insertions, 3 deletions
diff --git a/srfi/ChangeLog b/srfi/ChangeLog index 6ae7274ff..40afe47b5 100644 --- a/srfi/ChangeLog +++ b/srfi/ChangeLog @@ -1,3 +1,15 @@ +2001-05-02 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> + + * Makefile.am (srfi_DATA): Added srfi-10.scm and srfi-17.scm. + + * srfi-10.scm: New file. + + * srfi-17.scm: New file, contributed by Matthias Koeppe. Thanks a + lot! + Added `Commentary:' tag. + + * srfi-9.scm: Added `Commentary:' tag. + 2001-04-27 Rob Browning <rlb@cs.utexas.edu> * srfi-13.h diff --git a/srfi/Makefile.am b/srfi/Makefile.am index 5eb8eb9cc..11c25b8d9 100644 --- a/srfi/Makefile.am +++ b/srfi/Makefile.am @@ -21,8 +21,6 @@ AUTOMAKE_OPTIONS = foreign -#info_TEXINFOS = guile-srfi.texi - ## Prevent automake from adding extra -I options DEFS = @DEFS@ ## Check for headers in $(srcdir)/.., so that #include @@ -43,9 +41,11 @@ srfi_DATA = srfi-2.scm \ srfi-6.scm \ srfi-8.scm \ srfi-9.scm \ + srfi-10.scm \ srfi-11.scm \ srfi-13.scm \ - srfi-14.scm + srfi-14.scm \ + srfi-17.scm EXTRA_DIST = $(srfi_DATA) diff --git a/srfi/srfi-10.scm b/srfi/srfi-10.scm new file mode 100644 index 000000000..0ce743af3 --- /dev/null +++ b/srfi/srfi-10.scm @@ -0,0 +1,85 @@ +;;;; srfi-10.scm --- SRFI-10 read hash extension for Guile +;;;; +;;;; Copyright (C) 2001 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., 59 Temple Place, Suite 330, +;;;; Boston, MA 02111-1307 USA + +;;; Commentary: + +;;; This module implements the syntax extension #,(), also called +;;; hash-comma, which is defined in SRFI-10. +;;; +;;; The support for SRFI-10 consists of the procedure +;;; `define-reader-ctor' for defining new reader constructors and the +;;; read syntax form +;;; +;;; #,(<ctor> <datum> ...) +;;; +;;; where <ctor> must be a symbol for which a read constructor was +;;; defined previously. +;;; +;;; Example: +;;; +;;; (define-reader-ctor 'file open-input-file) +;;; (define f '#,(file "/etc/passwd")) +;;; (read-line f) +;;; => +;;; :root:x:0:0:root:/root:/bin/bash" +;;; +;;; Please note the quote before the #,(file ...) expression. This is +;;; necessary because ports are not self-evaluating in Guile. + +;;; Code: + +(define-module (srfi srfi-10) + #:use-module (ice-9 rdelim)) + +(export define-reader-ctor) + +;; This hash table stores the association between comma-hash tags and +;; the corresponding constructor procedures. +;; +(define reader-ctors (make-hash-table 31)) + +;; This procedure installs the procedure @var{proc} as the constructor +;; for the comma-hash tag @var{symbol}. +;; +(define (define-reader-ctor symbol proc) + (hashq-set! reader-ctors symbol proc) + (if #f #f)) ; Return unspecified value. + +;; Retrieve the constructor procedure for the tag @var{symbol} or +;; throw an error if no such tag is defined. +;; +(define (lookup symbol) + (let ((p (hashq-ref reader-ctors symbol #f))) + (if (procedure? p) + p + (error "unknown hash-comma tag " symbol)))) + +;; This is the actual reader extension. +;; +(define (hash-comma char port) + (let* ((obj (read port))) + (if (and (list? obj) (positive? (length obj)) (symbol? (car obj))) + (let ((p (lookup (car obj)))) + (let ((res (apply p (cdr obj)))) + res)) + (error "syntax error in hash-comma expression")))) + +;; Install the hash extension. +;; +(read-hash-extend #\, hash-comma) diff --git a/srfi/srfi-17.scm b/srfi/srfi-17.scm new file mode 100644 index 000000000..1a82ea09d --- /dev/null +++ b/srfi/srfi-17.scm @@ -0,0 +1,99 @@ +;;;; srfi-17.scm --- SRFI-17 procedures for Guile + +;;; Copyright (C) 2001 Free Software Foundation, Inc. +;;; Originally by Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> +;;; +;;; 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., 59 Temple Place, Suite 330, +;;; Boston, MA 02111-1307 USA + +;;; Commentary: + +;; This is an implementation of SRFI-17: Generalized set! +;; +;; It exports the Guile procedure `make-procedure-with-setter' under +;; the SRFI name `getter-with-setter' and exports the standard +;; procedures `car', `cdr', ..., `cdddr', `string-ref' and +;; `vector-ref' as procedures with setters, as required by the SRFI. +;; +;; SRFI-17 was heavily criticized during its discussion period but it +;; was finalized anyway. One issue was its concept of globally +;; associating setter "properties" with (procedure) values, which is +;; non-Schemy. For this reason, this implementation chooses not to +;; provide a way to set the setter of a procedure. In fact, (set! +;; (setter PROC) SETTER) signals an error. The only way to attach a +;; setter to a procedure is to create a new object (a "procedure with +;; setter") via the `getter-with-setter' procedure. This procedure is +;; also specified in the SRFI. Using it avoids the described +;; problems. + +;;; Code: + +(define-module (srfi srfi-17) + :export (getter-with-setter + setter + ;; redefined standard procedures + car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar + cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr + caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr + cdddar cddddr string-ref vector-ref)) + +;;; Procedures + +(define getter-with-setter make-procedure-with-setter) + +(define setter + (getter-with-setter + setter + (lambda args + (error "Setting setters is not supported for a good reason.")))) + +;;; Redefine R5RS procedures to appropriate procedures with setters + +(define (compose-setter setter location) + (lambda (obj value) + (setter (location obj) value))) + +(define car (getter-with-setter car set-car!)) +(define cdr (getter-with-setter cdr set-cdr!)) +(define caar (getter-with-setter caar (compose-setter set-car! car))) +(define cadr (getter-with-setter cadr (compose-setter set-car! cdr))) +(define cdar (getter-with-setter cdar (compose-setter set-cdr! car))) +(define cddr (getter-with-setter cddr (compose-setter set-cdr! cdr))) +(define caaar (getter-with-setter caaar (compose-setter set-car! caar))) +(define caadr (getter-with-setter caadr (compose-setter set-car! cadr))) +(define cadar (getter-with-setter cadar (compose-setter set-car! cdar))) +(define caddr (getter-with-setter caddr (compose-setter set-car! cddr))) +(define cdaar (getter-with-setter cdaar (compose-setter set-cdr! caar))) +(define cdadr (getter-with-setter cdadr (compose-setter set-cdr! cadr))) +(define cddar (getter-with-setter cddar (compose-setter set-cdr! cdar))) +(define cdddr (getter-with-setter cdddr (compose-setter set-cdr! cddr))) +(define caaaar (getter-with-setter caaaar (compose-setter set-car! caaar))) +(define caaadr (getter-with-setter caaadr (compose-setter set-car! caadr))) +(define caadar (getter-with-setter caadar (compose-setter set-car! cadar))) +(define caaddr (getter-with-setter caaddr (compose-setter set-car! caddr))) +(define cadaar (getter-with-setter cadaar (compose-setter set-car! cdaar))) +(define cadadr (getter-with-setter cadadr (compose-setter set-car! cdadr))) +(define caddar (getter-with-setter caddar (compose-setter set-car! cddar))) +(define cadddr (getter-with-setter cadddr (compose-setter set-car! cdddr))) +(define cdaaar (getter-with-setter cdaaar (compose-setter set-cdr! caaar))) +(define cdaadr (getter-with-setter cdaadr (compose-setter set-cdr! caadr))) +(define cdadar (getter-with-setter cdadar (compose-setter set-cdr! cadar))) +(define cdaddr (getter-with-setter cdaddr (compose-setter set-cdr! caddr))) +(define cddaar (getter-with-setter cddaar (compose-setter set-cdr! cdaar))) +(define cddadr (getter-with-setter cddadr (compose-setter set-cdr! cdadr))) +(define cdddar (getter-with-setter cdddar (compose-setter set-cdr! cddar))) +(define cddddr (getter-with-setter cddddr (compose-setter set-cdr! cdddr))) +(define string-ref (getter-with-setter string-ref string-set!)) +(define vector-ref (getter-with-setter vector-ref vector-set!)) diff --git a/srfi/srfi-9.scm b/srfi/srfi-9.scm index fb61dfec0..7d2468892 100644 --- a/srfi/srfi-9.scm +++ b/srfi/srfi-9.scm @@ -17,6 +17,8 @@ ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ;;;; Boston, MA 02111-1307 USA +;;; Commentary: + ;;; This module exports the syntactic form `define-record-type', which ;;; is the means for creating record types defined in SRFI-9. ;;; @@ -55,6 +57,8 @@ ;;; guile> (foo? 1) ;;; #f +;;; Code: + (define-module (srfi srfi-9)) (export-syntax define-record-type) |