From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rob Browning Newsgroups: gmane.lisp.guile.devel Subject: Switching to a SRFI-45 compliant force/delay. Date: Sun, 10 Sep 2006 16:24:56 -0700 Message-ID: <87ejujpanr.fsf@raven.defaultvalue.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1157930724 12690 80.91.229.2 (10 Sep 2006 23:25:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 10 Sep 2006 23:25:24 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Sep 11 01:25:22 2006 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GMYfk-0001Mv-2F for guile-devel@m.gmane.org; Mon, 11 Sep 2006 01:25:09 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GMYfh-0001zs-Sy for guile-devel@m.gmane.org; Sun, 10 Sep 2006 19:25:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GMYff-0001yS-JU for guile-devel@gnu.org; Sun, 10 Sep 2006 19:25:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GMYfd-0001uq-A3 for guile-devel@gnu.org; Sun, 10 Sep 2006 19:25:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GMYfd-0001ud-7Z for guile-devel@gnu.org; Sun, 10 Sep 2006 19:25:01 -0400 Original-Received: from [70.85.129.156] (helo=defaultvalue.org) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GMYgm-0002G3-3h for guile-devel@gnu.org; Sun, 10 Sep 2006 19:26:12 -0400 Original-Received: from omen.defaultvalue.org (localhost [127.0.0.1]) by defaultvalue.org (Postfix) with ESMTP id C204E90D5F for ; Sun, 10 Sep 2006 16:24:57 -0700 (PDT) Original-Received: from raven.defaultvalue.org (raven.defaultvalue.org [192.168.1.7]) by omen.defaultvalue.org (Postfix) with ESMTP id 7A62223D99 for ; Sun, 10 Sep 2006 16:24:57 -0700 (PDT) Original-Received: by raven.defaultvalue.org (Postfix, from userid 1000) id 6C13B355014; Sun, 10 Sep 2006 16:24:56 -0700 (PDT) Original-To: guile-devel@gnu.org User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6075 Archived-At: A while ago, I finished a SRFI-45 compliant force/delay/eager implementation for Guile, the core of which is more or less a translation of the SRFI reference code. (I started this in part with an eye toward lazy process streams, i.e. "find -printf ..." -> lazy-stream-of-lines) The implementation works (it passes all of the tests they provide), and I believe could completely replace Guile's existing eval.c force/delay, but I wanted to know if anyone knew of a reason it shouldn't. One notable difference is that this implementation is pure Scheme code (I have the eval.c force/delay commented out here). Below is what the current code looks like (just to give you a rough idea). Of course we would s/newforce/force/g and s/newdelay/delay/g before actually incorporating it. (define-module (ice-9 srfi-45) :use-module (ice-9 threads)) (export newforce) (export-syntax newdelay) (export eager) (export-syntax lazy) (define (print-promise promise port) (with-mutex (promise-mutex promise) (display "#"))) (define promise-type (make-record-type "promise" '(mutex data) print-promise)) (define promise-data (record-accessor promise-type 'data)) (define set-promise-data! (record-modifier promise-type 'data)) (define promise-mutex (record-accessor promise-type 'mutex)) (define make-promise (let ((constructor (record-constructor promise-type '(mutex data)))) (lambda (kind val) (constructor (make-recursive-mutex) (cons kind val))))) (define (promise-kind p) (car (promise-data p))) (define (set-promise-kind! p v) (set-car! (promise-data p) v)) (define (promise-value p) (cdr (promise-data p))) (define (set-promise-value! p v) (set-cdr! (promise-data p) v)) ;; need to finish this one... ;;(define promise? ;; "Return true if @var{obj} is a promise, i.e. a delayed computation\n(@pxref{Delayed evaluation,,,r5rs.info,The Revised^5 Report on Scheme})." ;; (record-predicate promise-type)) (define-macro (newdelay exp) `(lazy (eager ,exp))) (define (eager exp) (make-promise 'eager exp)) (define-macro (lazy exp) `((@@ (ice-9 srfi-45) make-promise) 'lazy (lambda () ,exp))) (define (newforce promise) (define (force-aux p) (case (promise-kind p) ((eager) (promise-value promise)) ((lazy) (let* ((promise* ((promise-value p)))) (if (not (eq? 'eager (promise-kind p))) (begin (set-promise-kind! p (promise-kind promise*)) (set-promise-value! p (promise-value promise*)) (set-promise-data! promise* (promise-data p)) ) ) (force-aux p))))) (with-mutex (promise-mutex promise) (force-aux promise))) -- Rob Browning rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu GPG starting 2002-11-03 = 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel