Commit | Line | Data |
---|---|---|
3514320f MV |
1 | ;;; srfi-39.scm --- Parameter objects |
2 | ||
0c65f52c | 3 | ;; Copyright (C) 2004, 2005, 2006, 2008, 2011 Free Software Foundation, Inc. |
3514320f | 4 | ;; |
d3cf93bc NJ |
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 | |
83ba2d37 | 8 | ;; version 3 of the License, or (at your option) any later version. |
3514320f | 9 | ;; |
d3cf93bc | 10 | ;; This library is distributed in the hope that it will be useful, |
3514320f MV |
11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
d3cf93bc | 13 | ;; Lesser General Public License for more details. |
3514320f | 14 | ;; |
d3cf93bc NJ |
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 | |
3514320f MV |
18 | |
19 | ;;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org> | |
20 | ;;; Date: 2004-05-05 | |
21 | ||
22 | ;;; Commentary: | |
23 | ||
24 | ;; This is an implementation of SRFI-39 (Parameter objects). | |
25 | ;; | |
26 | ;; The implementation is based on Guile's fluid objects, and is, therefore, | |
27 | ;; thread-safe (parameters are thread-local). | |
28 | ;; | |
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. | |
33 | ;; | |
34 | ||
35 | ;;; Code: | |
36 | ||
37 | (define-module (srfi srfi-39) | |
3514320f | 38 | ;; helper procedure not in srfi-39. |
b9f69396 | 39 | #:export (with-parameters*) |
9670f238 AW |
40 | #:re-export (make-parameter |
41 | parameterize | |
42 | current-input-port current-output-port current-error-port)) | |
3514320f | 43 | |
edb6de0b MW |
44 | (cond-expand-provide (current-module) '(srfi-39)) |
45 | ||
3514320f | 46 | (define (with-parameters* params values thunk) |
b9f69396 KR |
47 | (let more ((params params) |
48 | (values values) | |
49 | (fluids '()) ;; fluids from each of PARAMS | |
9670f238 | 50 | (convs '())) ;; VALUES with conversion proc applied |
b9f69396 | 51 | (if (null? params) |
9670f238 AW |
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))))) |