Singleton: Difference between revisions

Content added Content deleted
(Add Racket example)
Line 1,162:
EndClass</lang>
 
=={{header|Racket}}==
 
Singletons are not very useful in Racket, because functions that use module state are more straightforward. However, it is possible to construct one by simply not exporting the class value that constructs the singleton:
 
<lang lisp>
#lang racket
 
(provide instance)
 
(define singleton%
(class object%
(super-new)))
 
(define instance (new singleton%))
</lang>
 
=={{header|Ruby}}==