[plt-scheme] Singleton pattern using class.ss

From: Stephen De Gabrielle (stephen at degabrielle.name)
Date: Wed Dec 12 09:58:59 EST 2007

Should I try swindle?(tiny-clos)

The section 'Classes are instances
too<http://pre.plt-scheme.org/docs/html/t-y-scheme/t-y-scheme-Z-H-1.html#node_toc_node_sec_12.2>'
in t-y-scheme addresses this too
http://pre.plt-scheme.org/docs/html/t-y-scheme/t-y-scheme-Z-H-14.html#node_sec_12.2

Cheers,

Stephen

On Dec 12, 2007 2:33 PM, Stephen De Gabrielle <stephen at degabrielle.name>
wrote:

> Thank  you!
>
> Yes it does help.
>
> I'm trying to work out the class.ss equivalent of java class methods and
> fields like this;
>
> public class ActivityManager extends Thread {
> > [...]
> >    private synchronized static ActivityManager getInstance() {
> >         if ( s_instance == null || !s_instance.isAlive() ) {
> >            s_instance = new ActivityManager();
> >        }
> >        return s_instance;
> >    }
> >
> [code from prefuse.org; I'm porting bits to scheme]
>
> Do you mind if I put your example in the scheme cookbook?
> (in or near http://schemecookbook.org/Cookbook/IntroductionToMzlibClasses)
>
> The 'Factory Pattern' is next for me. Any suggestions gratefully accepted.
>
>
> Cheers,
>
>
> Stephen
>
>
>
>
>
>
> On Dec 11, 2007 2:58 AM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> > 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
> >
> >
> >
>
>
>
> --
>
> Cheers,
>
> Stephen
>
>
>
> --
> Stephen De Gabrielle
> s.degabrielle at ucl.ac.uk
> Telephone +44 (0)20 7679 5242 (x45242)
> Mobile                  079 851 890 45
> http://www.uclic.ucl.ac.uk/annb/MaSI.html
> University College London Interaction Centre
> Remax House - 31/32 Alfred Place
> London - WC1E 7DP
>



-- 
Cheers,

Stephen



--
Stephen De Gabrielle
s.degabrielle at ucl.ac.uk
Telephone +44 (0)20 7679 5242 (x45242)
Mobile                  079 851 890 45
http://www.uclic.ucl.ac.uk/annb/MaSI.html
University College London Interaction Centre
Remax House - 31/32 Alfred Place
London - WC1E 7DP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071212/f43d26cd/attachment.html>

Posted on the users mailing list.