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 Subject: Re: srfi-39 implementation Date: Fri, 14 May 2004 01:23:52 +0200 Organization: CCD - Autonomous University of Barcelona Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <871xlnq5br.fsf@holmes.localdomain> References: <20040506010251.GA3066@uab.es> <87brky5su3.fsf@zip.com.au> <87brkxf7yl.fsf@holmes.localdomain> <87oeos119q.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1084491803 21422 80.91.224.253 (13 May 2004 23:43:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 13 May 2004 23:43:23 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri May 14 01:43:13 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 1BOPr6-0000ji-01 for ; Fri, 14 May 2004 01:43:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BOPp2-0001PR-Iy for guile-devel@m.gmane.org; Thu, 13 May 2004 19:41:04 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BOPor-0001OO-GD for guile-devel@gnu.org; Thu, 13 May 2004 19:40:53 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BOPoK-0001JN-08 for guile-devel@gnu.org; Thu, 13 May 2004 19:40:52 -0400 Original-Received: from [80.33.152.103] (helo=holmes.localdomain) by monty-python.gnu.org with esmtp (TLSv1:RC4-SHA:128) (Exim 4.34) id 1BOPYW-0006Pz-JJ for guile-devel@gnu.org; Thu, 13 May 2004 19:24:01 -0400 Original-Received: from jao by holmes.localdomain with local (Exim 4.34) id 1BOPYP-0004mX-5Q; Fri, 14 May 2004 01:23:53 +0200 Original-To: guile-devel@gnu.org X-Attribution: jao X-URL: Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAYFBMVEUICAj////4+Pjw8PAY GBhYWFjg4OAQEBDQ0NC4uLjo6OjIyMg4ODggICBgYGBAQEAoKCiIiIhQUFCYmJiwsLBoaGiQkJBw cHCAgICgoKBISEgwMDCoqKjY2NjAwMB4eHjpzs9HAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEgAA CxIB0t1+/AAAAAd0SU1FB9MMFhUWOMaLTbEAAAHBSURBVHic1VXLoqMgDDUgKIIiiPVt//8vb2jV 3s60IruZbMjinOTkYUyS/8LKMpIgizmO4gDyKIYmBEQMoS4AIIskRGVQBKCPIWgk6M3PrkizAHRz x4IIFiTcsa34lMysFMuHpQoQZiQ0wrcKDeVBcQJOx35FDCEFl2Iw99aytqq/gVXv4yKeMxUu1gqO yYWxA8AcRKNlnZx98kwChKp8M5wzjVq9DsDF4BNxKJrEhaElEwH+UDQ12ASSBykGoMGHSQqPMdP0 HJ9yIKNuCuD9VGIK6AIJ2GMdimFEX6O7hhThEPjaPmXckKoDeAy6uC471DWhBA6oKofceh/LzwMV +3vhY7ZFkyaKYvmhBII8Z8CoVPKCIAZkG7Kl9IKgjL/2uoWD/N3Mr5jYXiKnc7yiVO3+jcBC8cM7 FbSAPQQRkCkjQG4nhAHM7iLUi+v9tqpv+PYVzVJwj2Ebv1fm8zlQ9MBj/NsGGvxV4p+6VecHvqL8 WOlMeAbIv4ov1/sOMWT+dbfS/Hn+ZPU2xNLtMWuXvwuol+1iLuZVftrs/axc++c6KA6bUbcPMt01 KPthe0b/adNc9PrqtdId03XML++ftx9ClhEPheraiAAAAABJRU5ErkJggg== In-Reply-To: <87oeos119q.fsf@zip.com.au> (Kevin Ryde's message of "Fri, 14 May 2004 07:10:41 +1000") User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) 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:3711 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3711 --=-=-= Kevin Ryde writes: > "Jose A. Ortega Ruiz" writes: >> >> Although you are right in that primitive-make-property & co. can be >> used, i think the case-based thing is slightly lighter and maybe even >> faster, since no hashtable creation/lookup is involved. Or, at any >> rate, the difference should be minimal, > > Ok. Another possibility I guess (for both styles) would be a single > call or lookup giving back both fluid and converter. Doesn't quite > suit the way with-parameters* does its `map's though. > Yes. I cannot think at the moment of a simple way of using a single call---all that comes to mind involves call-with-values, fold or the like, and makes the code more complex. >> (define-module (srfi srfi-39) >> #:export (make-parameter) >> #:export-syntax (parameterize) >> >> ;; procedure not in srfi-39. >> #:export (with-parameters*)) > > One #:export (with whatever comment) is enough I expect. > OK. > > In emacs > > (put 'with-test-prefix 'scheme-indent-function 1) > [...] Ah. Thanks for the tip. I had overlooked it. > >> (let ((conv (lambda (x) (if (x > 10) 10 x)))) >> (pass-if "converter 1" (let ((a (make-parameter 32))) (eqv? (a) 32))) > > A leftover from something? conv seems unused, and "(x > 10)" looks > pretty doubtful. > Ooops. An error. 'conv', or rather, a correct version of it, was meant to be used in the tests within the 'let'. I've corrected it. > Otherwise looks good to me. Great. Please find attached a new version of both files that, hopefully, addresses the above issues (except the single lookup). Best regards, jao -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. - Blair Houghton. --=-=-= Content-Type: application/octet-stream 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 procedure 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) #:export (make-parameter with-parameters*) ;; procedure not in srfi-39. #:export-syntax (parameterize)) (define fluid-prop (list 0)) (define conv-prop (list 0)) (define (make-parameter val . conv) (let ((value (make-fluid)) (conv (if (null? conv) identity (if (null? (cdr conv)) (car conv) (scm-error 'wrong-number-of-args "make-parameter" "Wrong number of arguments"))))) (fluid-set! value (conv val)) (lambda new-value (cond ((null? new-value) (fluid-ref value)) ((null? (cdr new-value)) (fluid-set! value (conv (car new-value)))) ((eq? (cadr new-value) fluid-prop) value) ; used by parameterize ((eq? (cadr new-value) conv-prop) conv) ; ditto (else (error "A parameter expects 0 or 1 arguments" new-value)))))) (define-macro (parameterize params . body) `(with-parameters* (list ,@(map car params)) (list ,@(map cadr params)) (lambda () ,@body))) (define (with-parameters* params values thunk) (with-fluids* (map (lambda (p) (p #f fluid-prop)) params) (map (lambda (p v) ((p #f conv-prop) v)) params values) thunk)) ; arch-tag: 536b6766-9947-4ad0-a35e-2420000d8a72 --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=srfi-39.test Content-Transfer-Encoding: base64 Ozsgc3JmaS0zOS50ZXN0IC0tIFRlc3Qgc3VpdGUgZm9yIFNSRkktMzkncyBmdW5jdGlvbnMuIC0q LSBzY2hlbWUgLSotCgo7OyBDb3B5cmlnaHQgKEMpIDIwMDQgRnJlZSBTb2Z0d2FyZSBGb3VuZGF0 aW9uLCBJbmMuCjs7IEF1dGhvcjogSm9zZSBBIE9ydGVnYSBSdWl6IDxqYW9AZ251Lm9yZz4KOzsg RGF0ZTogTW9uIE1heSAxMCwgMjAwNCAwMDoxOQoKOzsKOzsgVGhpcyBwcm9ncmFtIGlzIGZyZWUg c29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBtb2RpZnkKOzsgaXQgdW5k ZXIgdGhlIHRlcm1zIG9mIHRoZSBHTlUgR2VuZXJhbCBQdWJsaWMgTGljZW5zZSBhcyBwdWJsaXNo ZWQgYnkKOzsgdGhlIEZyZWUgU29mdHdhcmUgRm91bmRhdGlvbjsgZWl0aGVyIHZlcnNpb24gMiBv ZiB0aGUgTGljZW5zZSwgb3IKOzsgKGF0IHlvdXIgb3B0aW9uKSBhbnkgbGF0ZXIgdmVyc2lvbi4K OzsKOzsgVGhpc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SkpKQoK KHdpdGgtdGVzdC1wcmVmaXggInBhcmFtZXRlcml6ZSIKCiAgKGxldCogKChhIChtYWtlLXBhcmFt ZXRlciAxMCkpCiAgICAgICAgIChiIChtYWtlLXBhcmFtZXRlciAyMCkpCiAgICAgICAgIChjICht YWtlLXBhcmFtZXRlciAyIChsYW1iZGEgKHgpIChpZiAoPCB4IDEwKSB4IDEwKSkpKQogICAgICAg ICAoZCAobWFrZS1wYXJhbWV0ZXIgMSAobGFtYmRhICh4KSAoaWYgKDwgeCAxMCkgeCAxMCkpKSkK ICAgICAgICAgKHRlc3QtdmFsdWVzIChsYW1iZGEgKHggeSB6IHcpCiAgICAgICAgICAgICAgICAg ICAgICAgIChhbmQgKGVxdj8gKGEpIHgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGVx dj8gKGIpIHkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGVxdj8gKGMpIHopCiAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgKGVxdj8gKGQpIHcpKSkpKQoKICAgIChwYXNzLWlmICJz aW1wbGUiCiAgICAgIChhbmQKICAgICAgICh0ZXN0LXZhbHVlcyAxMCAyMCAyIDEpCiAgICAgICAo cGFyYW1ldGVyaXplICgoYSAyKSAoYiAxKSkgKHRlc3QtdmFsdWVzIDIgMSAyIDEpKQogICAgICAg KHRlc3QtdmFsdWVzIDEwIDIwIDIgMSkpKQoKICAgIChwYXNzLWlmICJuZXN0ZWQiCiAgICAgIChh bmQKICAgICAgICh0ZXN0LXZhbHVlcyAxMCAyMCAyIDEpCiAgICAgICAocGFyYW1ldGVyaXplICgo YSAyKSAoYiAxKSkKICAgICAgICAgKGFuZCAodGVzdC12YWx1ZXMgMiAxIDIgMSkKICAgICAgICAg ICAgICAocGFyYW1ldGVyaXplICgoZCA4KSkgKHRlc3QtdmFsdWVzIDIgMSAyIDgpKQogICAgICAg ICAgICAgICh0ZXN0LXZhbHVlcyAyIDEgMiAxKSkpCiAgICAgICAodGVzdC12YWx1ZXMgMTAgMjAg MiAxKSkpCgogICAgKHBhc3MtaWYgInNpbXBsZSB3aXRoIGNvbnZlcnRlciIKICAgICAgKGFuZAog ICAgICAgKHRlc3QtdmFsdWVzIDEwIDIwIDIgMSkKICAgICAgIChwYXJhbWV0ZXJpemUgKChjIDQz KSAoZCAxKSkgKHRlc3QtdmFsdWVzIDEwIDIwIDEwIDEpKQogICAgICAgKHRlc3QtdmFsdWVzIDEw IDIwIDIgMSkKICAgICAgIChwYXJhbWV0ZXJpemUgKChhIDEpIChjIDEwMCkgKGQgMjEpKSAodGVz dC12YWx1ZXMgMSAyMCAxMCAxMCkpCiAgICAgICAodGVzdC12YWx1ZXMgMTAgMjAgMiAxKSkpCgog ICAgKHBhc3MtaWYgIm5lc3RlZCB3aXRoIGNvbnZlcnRlciIKICAgICAgKGFuZAogICAgICAgKHRl c3QtdmFsdWVzIDEwIDIwIDIgMSkKICAgICAgIChwYXJhbWV0ZXJpemUgKChjIDI0KSAoYiAxKSkK ICAgICAgICAgKGFuZCAodGVzdC12YWx1ZXMgMTAgMSAxMCAxKQogICAgICAgICAgICAgIChwYXJh bWV0ZXJpemUgKChkIDg4KSkKICAgICAgICAgICAgICAgIChhIDE1KQogICAgICAgICAgICAgICAg KGFuZAogICAgICAgICAgICAgICAgICh0ZXN0LXZhbHVlcyAxNSAxIDEwIDEwKQogICAgICAgICAg ICAgICAgIChwYXJhbWV0ZXJpemUgKChkIDMpKSAodGVzdC12YWx1ZXMgMTUgMSAxMCAzKSkKICAg ICAgICAgICAgICAgICAodGVzdC12YWx1ZXMgMTUgMSAxMCAxMCkpKQogICAgICAgICAgICAgICh0 ZXN0LXZhbHVlcyAxNSAxIDEwIDEpKSkKICAgICAgICh0ZXN0LXZhbHVlcyAxNSAyMCAyIDEpKSkp KQo= --=-=-= 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 --=-=-=--