Subject: Re: Lisp and Scheme
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 29 Oct 2000 12:04:56 GMT
Newsgroups: comp.lang.scheme
Message-ID: <8th3p8$9f9aa$1@fido.engr.sgi.com>
FM <danfm@dartmouth.edu> wrote:
+---------------
| but something like this isn't so trivially transformed:
| 
| (let ((x 1))
|   (defun gen ()
|     (incf x))
|   (defun gen2 ()
|     (decf x)))
+---------------

The usual [albeit somewhat ugly] Scheme idiom for this is:

(define gen 'notyet)
(define gen2 'notyet)
(let ((x 1))
  (set! gen (lambda () (set! x (+ x 1)) x))
  (set! gen2 (lambda () (set! x (- x 1)) x)))


-Rob

-----
Rob Warnock, 31-2-510		rpw3@sgi.com
Network Engineering		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043