[plt-scheme] Singleton pattern using class.ss
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%
(super-new)
(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