singleton docs
							parent
							
								
									8b22f4436b
								
							
						
					
					
						commit
						7ec68e0aa7
					
				| 
						 | 
				
			
			@ -47,6 +47,7 @@ $nl
 | 
			
		|||
"Other sorts of classes:"
 | 
			
		||||
{ $subsection "builtin-classes" }
 | 
			
		||||
{ $subsection "unions" }
 | 
			
		||||
{ $subsection "singletons" }
 | 
			
		||||
{ $subsection "mixins" }
 | 
			
		||||
{ $subsection "predicates" }
 | 
			
		||||
"Classes can be inspected and operated upon:"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,11 @@
 | 
			
		|||
USING: help.markup help.syntax kernel words ;
 | 
			
		||||
IN: classes.singleton
 | 
			
		||||
 | 
			
		||||
ARTICLE: "singletons" "Singleton classes"
 | 
			
		||||
"A singleton is a class with only one instance and with no state.  Methods may dispatch off of singleton classes."
 | 
			
		||||
{ $subsection POSTPONE: SINGLETON: }
 | 
			
		||||
{ $subsection define-singleton-class } ;
 | 
			
		||||
 | 
			
		||||
HELP: SINGLETON:
 | 
			
		||||
{ $syntax "SINGLETON: class"
 | 
			
		||||
} { $values
 | 
			
		||||
| 
						 | 
				
			
			@ -8,7 +13,16 @@ HELP: SINGLETON:
 | 
			
		|||
} { $description
 | 
			
		||||
    "Defines a new predicate class whose superclass is " { $link word } ".  Only one instance of a singleton may exist because classes are " { $link eq? } " to themselves.  Methods may be defined on a singleton."
 | 
			
		||||
} { $examples
 | 
			
		||||
    { $example "USING: singleton kernel io ;" "SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
 | 
			
		||||
    { $example "USING: classes.singleton kernel io ;" "SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
 | 
			
		||||
} { $see-also
 | 
			
		||||
    POSTPONE: PREDICATE:
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
HELP: define-singleton-class
 | 
			
		||||
{ $values { "word" "a new word" } }
 | 
			
		||||
{ $description
 | 
			
		||||
    "Defines a newly created word to be a singleton class." } ;
 | 
			
		||||
 | 
			
		||||
{ POSTPONE: SINGLETON: define-singleton-class } related-words
 | 
			
		||||
 | 
			
		||||
ABOUT: "singletons"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue