rewrite singletons to be predicate classes instead of tuples
parent
677a1f81ca
commit
3652a454d8
|
@ -1,14 +1,14 @@
|
||||||
USING: help.markup help.syntax ;
|
USING: help.markup help.syntax kernel words ;
|
||||||
IN: singleton
|
IN: singleton
|
||||||
|
|
||||||
HELP: SINGLETON:
|
HELP: SINGLETON:
|
||||||
{ $syntax "SINGLETON: class"
|
{ $syntax "SINGLETON: class"
|
||||||
} { $values
|
} { $values
|
||||||
{ "class" "a new tuple class to define" }
|
{ "class" "a new singleton to define" }
|
||||||
} { $description
|
} { $description
|
||||||
"Defines a new tuple class with membership predicate name? and a default empty constructor that is the class name itself."
|
"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
|
} { $examples
|
||||||
{ $example "SINGLETON: foo\nfoo ." "T{ foo f }" }
|
{ $example "SINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
|
||||||
} { $see-also
|
} { $see-also
|
||||||
POSTPONE: TUPLE:
|
POSTPONE: PREDICATE:
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
! Copyright (C) 2007 Doug Coleman.
|
! Copyright (C) 2007 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel parser quotations prettyprint tuples words ;
|
USING: classes.predicate kernel parser quotations words ;
|
||||||
IN: singleton
|
IN: singleton
|
||||||
|
|
||||||
|
|
||||||
: SINGLETON:
|
: SINGLETON:
|
||||||
|
\ word
|
||||||
CREATE-CLASS
|
CREATE-CLASS
|
||||||
dup { } define-tuple-class
|
dup [ eq? ] curry define-predicate-class ; parsing
|
||||||
dup unparse create-in reset-generic
|
|
||||||
dup construct-empty 1quotation define ; parsing
|
|
||||||
|
|
Loading…
Reference in New Issue