For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - Gauche extensions   [Contents][Index]

9.20 gauche.mop.singleton - Singleton

Module: gauche.mop.singleton

Provides a metaclass to define a singleton class.

Class: <singleton-meta>

{gauche.mop.singleton} Creates a singleton class. A singleton class is a class that is guaranteed to create only one instance. The first invocation of make creates the single instance, and further attempt of creation returns the same instance.

(define-class single () () :metaclass <singleton-meta>)

(define a (make single))
(define b (make single))

(eq? a b) ⇒ #t

The slots of the instance are initialized at the first invocation of make. Initargs of make are effective only in the fist invocation, and ignored in the subsequent invocation.

The call of initialization in make is thread-safe.

Method: instance-of (class <singleton-meta>) :rest initargs

{gauche.mop.singleton} This method just calls make with the passed arguments. It is more obvious in the program that you’re dealing with singleton.

Class: <singleton-mixin>

{gauche.mop.singleton} An instance of <singleton-meta>. Instead of specifying <singleton-meta> as the :metaclass argument of define-class, you can inherit this class to give your class the property of singleton.


Next: , Previous: , Up: Library modules - Gauche extensions   [Contents][Index]


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT