Next: gauche.mop.validator
- Slot with validator, Previous: gauche.mop.propagate
- Propagating slot access, Up: Library modules - Gauche extensions [Contents][Index]
gauche.mop.singleton
- SingletonProvides a metaclass to define a singleton class.
{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.
{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.
{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: gauche.mop.validator
- Slot with validator, Previous: gauche.mop.propagate
- Propagating slot access, Up: Library modules - Gauche extensions [Contents][Index]