[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's so cool about Scheme?




   Date: Wed, 4 Jun 2003 10:04:07 -0500
   From: Matt Hellige <matt@immute.net>
   To: ll1-discuss@ai.mit.edu
   Subject: Re: What's so cool about Scheme?
   
   [Guy Steele - Sun Microsystems Labs <Guy.Steele@sun.com>]
   > 
   > A closure is an object that supports exactly one method: "apply".
   > 
   
   What about this?
   
       (define get-balance #f)
       (define deposit #f)
   
       (let ((balance 0))
         (set! get-balance
               (lambda ()
                 balance))
         (set! deposit
               (lambda (amount)
                 (set! balance (+ balance amount))
                 balance)))
   
That's two closures that share some state ("balance").  Each closure
has been stored in a global variable ("get-balance", "deposit").
Each of the closures supports the method "apply".  One requires that
the ordered set of argument values be empty; the other requires that
the ordered set of argument values be a singleton set.

--Guy Steele