[plt-scheme] Singleton pattern using class.ss

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Dec 10 21:58:30 EST 2007

On Dec 10, 2007, at 8:48 PM, Stephen De Gabrielle wrote:

> Hi, I'm trying to replicate the 'singleton' pattern using class.ss,
> but I'm having a little trouble. Can anyone point of to an example?

One of the things you can do is instantiate a class once and export  
only that instance:

(module singleton mzscheme

   (require (lib "class.ss"))

   (define one%
     (class object%
       (define/public (hello) one))

   (define one (new one%))

   (provide one))

Inside the class you never use new; instead you refer to this  
instance. Does this help?

-- Matthias

Posted on the users mailing list.