;; -*-Mode: Scheme;-*- ;; ;; Copyright (C) 1995 Josh MacDonald ;; ;; Permission to use, copy, and/or distribute this software and its ;; documentation for any purpose and without fee is hereby granted, provided ;; that both the above copyright notice and this permission notice appear in ;; all copies and derived works. Fees for distribution or use of this ;; software or derived works may only be charged with express written ;; permission of the copyright holder. ;; This software is provided ``as is'' without express or implied warranty. ;; ;; try this in the environment diagrammer (its good for explaining ;; lexical scope, too) (define make-counter (let ((count 0)) (lambda () (let ((local-count 0)) (lambda (n) (set! count (+ count n)) (set! local-count (+ local-count n))))))) ;; (define c1 (make-counter)) ;; (define c2 (make-counter)) ;; (c1 20) ;; (c2 30) ;; (c1 30) ;; (c2 40)