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
|
||||
|
||||
HELP: SINGLETON:
|
||||
{ $syntax "SINGLETON: class"
|
||||
} { $values
|
||||
{ "class" "a new tuple class to define" }
|
||||
{ "class" "a new singleton to define" }
|
||||
} { $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
|
||||
{ $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
|
||||
POSTPONE: TUPLE:
|
||||
POSTPONE: PREDICATE:
|
||||
} ;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
! Copyright (C) 2007 Doug Coleman.
|
||||
! 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
|
||||
|
||||
|
||||
: SINGLETON:
|
||||
\ word
|
||||
CREATE-CLASS
|
||||
dup { } define-tuple-class
|
||||
dup unparse create-in reset-generic
|
||||
dup construct-empty 1quotation define ; parsing
|
||||
dup [ eq? ] curry define-predicate-class ; parsing
|
||||
|
|
Loading…
Reference in New Issue