From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jose A Ortega Ruiz Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.sources Subject: srfi-39 implementation Date: Thu, 6 May 2004 03:02:51 +0200 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <20040506010251.GA3066@uab.es> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="oyUTqETQ0mS9luUI" X-Trace: sea.gmane.org 1083805614 13860 80.91.224.253 (6 May 2004 01:06:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 6 May 2004 01:06:54 +0000 (UTC) Cc: guile-sources@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu May 06 03:06:44 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BLXLY-0007Qs-00 for ; Thu, 06 May 2004 03:06:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BLXIW-0005yf-A2 for guile-devel@m.gmane.org; Wed, 05 May 2004 21:03:36 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BLXIN-0005xL-Rj for guile-devel@gnu.org; Wed, 05 May 2004 21:03:27 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BLXHr-0005qi-FI for guile-devel@gnu.org; Wed, 05 May 2004 21:03:26 -0400 Original-Received: from [80.33.152.103] (helo=holmes.localdomain) by monty-python.gnu.org with esmtp (TLSv1:RC4-SHA:128) (Exim 4.30) id 1BLXHq-0005qE-DX; Wed, 05 May 2004 21:02:55 -0400 Original-Received: from jao by holmes.localdomain with local (Exim 4.32) id 1BLXHn-0000oC-8g; Thu, 06 May 2004 03:02:51 +0200 Original-To: guile-devel@gnu.org Content-Disposition: inline X-Operating-System: Linux holmes 2.6.4-1-686 User-Agent: Mutt/1.5.6i X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3676 gmane.lisp.guile.sources:122 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3676 --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi. Please find attached an implementation of SRFI-39 (parameter objects) for Guile. Following hints by dsmith and rlb in #guile, i've implemented it from scratch using Guile's fluids, which are already very close to parameters (unlike SRFI-39's reference implementation, this is thus a thread-safe implementation). It's nothing fancy (we already have fluids after all!), but including it would make Guile more buzzword-compliant ;-). So, I'd be glad to transfer the copyright to the FSF (if needed; it's barely 30 loc without comments) in case you deem convenient including it in future releases. Thanks for your time. Regards, jao --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="srfi-39.scm" ;;; srfi-39.scm --- Parameter objects ;; Copyright (C) 2004 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 ;; ;; As a special exception, the Free Software Foundation gives permission ;; for additional uses of the text contained in its release of GUILE. ;; ;; The exception is that, if you link the GUILE library with other files ;; to produce an executable, this does not by itself cause the ;; resulting executable to be covered by the GNU General Public License. ;; Your use of that executable is in no way restricted on account of ;; linking the GUILE library code into it. ;; ;; This exception does not however invalidate any other reasons why ;; the executable file might be covered by the GNU General Public License. ;; ;; This exception applies only to the code released by the ;; Free Software Foundation under the name GUILE. If you copy ;; code from other Free Software Foundation releases into a copy of ;; GUILE, as the General Public License permits, the exception does ;; not apply to the code that you add in this way. To avoid misleading ;; anyone as to the status of such modified files, you must delete ;; this exception notice from them. ;; ;; If you write modifications of your own for GUILE, it is your choice ;; whether to permit this exception to apply to your modifications. ;; If you do not wish that, delete this exception notice. ;;; Author: Jose Antonio Ortega Ruiz ;;; Date: 2004-05-05 ;;; Commentary: ;; This is an implementation of SRFI-39 (Parameter objects). ;; ;; The implementation is based on Guile's fluid objects, and is, therefore, ;; thread-safe (parameters are thread-local). ;; ;; In addition to the forms defined in SRFI-39 (`make-parameter', ;; `parameterize'), a new procedure `with-parameters*' is provided. ;; This procedures is analogous to `with-fluids*' but taking as first ;; argument a list of parameter objects instead of a list of fluids. ;; ;;; Code: (define-module (srfi srfi-39) #:use-module (ice-9 syncase) #:use-module (srfi srfi-16) #:export (make-parameter) #:export-syntax (parameterize) ;; helper procedure not in srfi-39. #:export (with-parameters*)) (define make-parameter (case-lambda ((val) (make-parameter/helper val (lambda (x) x))) ((val conv) (make-parameter/helper val conv)))) (define get-fluid-tag (lambda () 'get-fluid)) ;; arbitrary unique (as per eq?) value (define (make-parameter/helper val conv) (let ((value (make-fluid)) (conv conv)) (begin (fluid-set! value (conv val)) (lambda new-value (cond ((null? new-value) (fluid-ref value)) ((eq? (car new-value) get-fluid-tag) value) ((null? (cdr new-value)) (fluid-set! value (conv (car new-value)))) (else (error "make-parameter expects 0 or 1 arguments" new-value))))))) (define-syntax parameterize (syntax-rules () ((_ ((?param ?value) ...) ?body ...) (with-parameters* (list ?param ...) (list ?value ...) (lambda () ?body ...))))) (define (with-parameters* params values thunk) (with-fluids* (map (lambda (p) (p get-fluid-tag)) params) values thunk)) ; arch-tag: 536b6766-9947-4ad0-a35e-2420000d8a72 --oyUTqETQ0mS9luUI Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --oyUTqETQ0mS9luUI--