1 ;;; srfi-39.scm --- Parameter objects
3 ;; Copyright (C) 2004, 2005, 2006, 2008, 2011 Free Software Foundation, Inc.
5 ;; This library is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public
7 ;; License as published by the Free Software Foundation; either
8 ;; version 3 of the License, or (at your option) any later version.
10 ;; This library is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this library; if not, write to the Free Software
17 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 ;;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
24 ;; This is an implementation of SRFI-39 (Parameter objects).
26 ;; The implementation is based on Guile's fluid objects, and is, therefore,
27 ;; thread-safe (parameters are thread-local).
29 ;; In addition to the forms defined in SRFI-39 (`make-parameter',
30 ;; `parameterize'), a new procedure `with-parameters*' is provided.
31 ;; This procedures is analogous to `with-fluids*' but taking as first
32 ;; argument a list of parameter objects instead of a list of fluids.
37 (define-module (srfi srfi-39)
38 ;; helper procedure not in srfi-39.
39 #:export (with-parameters*)
40 #:re-export (make-parameter
42 current-input-port current-output-port current-error-port))
44 (cond-expand-provide (current-module) '(srfi-39))
46 (define (with-parameters* params values thunk)
47 (let more ((params params)
49 (fluids '()) ;; fluids from each of PARAMS
50 (convs '())) ;; VALUES with conversion proc applied
52 (with-fluids* fluids convs thunk)
53 (more (cdr params) (cdr values)
54 (cons (parameter-fluid (car params)) fluids)
55 (cons ((parameter-converter (car params)) (car values)) convs)))))