]> gitweb.factorcode.org Git - factor.git/blob - core/classes/classes-docs.factor
Fix permission bits
[factor.git] / core / classes / classes-docs.factor
1 USING: help.markup help.syntax kernel kernel.private
2 namespaces sequences words arrays layouts effects math
3 layouts classes.private classes.union classes.mixin
4 classes.predicate quotations ;
5 IN: classes
6
7 ARTICLE: "class-predicates" "Class predicate words"
8 "With a handful of exceptions, each class has a membership predicate word, named " { $snippet { $emphasis "class" } "?" } " . A quotation calling this predicate is stored in the " { $snippet "\"predicate\"" } " word property."
9 $nl
10 "When it comes to predicates, the exceptional classes are:"
11 { $table
12     { "Class" "Predicate" "Explanation" }
13     { { $link f } { $snippet "[ not ]" } { "The conventional name for a word which outputs true when given false is " { $link not } "; " { $snippet "f?" } " would be confusing." } }
14     { { $link object } { $snippet "[ drop t ]" } { "All objects are instances of " { $link object } } }
15     { { $link null } { $snippet "[ drop f ]" } { "No object is an instance of " { $link null } } }
16 }
17 "The set of class predicate words is a class:"
18 { $subsection predicate }
19 { $subsection predicate? }
20 "A predicate word holds a reference to the class it is predicating over in the " { $snippet "\"predicating\"" } " word property." ;
21
22 ARTICLE: "classes" "Classes"
23 "Conceptually, a " { $snippet "class" } " is a set of objects whose members can be identified with a predicate, and on which generic words can specialize methods. Classes are organized into a general partial order, and an object may be an instance of more than one class."
24 $nl
25 "At the implementation level, a class is a word with certain word properties set."
26 $nl
27 "Words for working with classes are found in the " { $vocab-link "classes" } " vocabulary."
28 $nl
29 "Classes themselves form a class:"
30 { $subsection class? }
31 "You can ask an object for its class:"
32 { $subsection class }
33 "Testing if an object is an instance of a class:"
34 { $subsection instance? }
35 "You can ask a class for its superclass:"
36 { $subsection superclass }
37 { $subsection superclasses }
38 "Class predicates can be used to test instances directly:"
39 { $subsection "class-predicates" }
40 "There is a universal class which all objects are an instance of, and an empty class with no instances:"
41 { $subsection object }
42 { $subsection null }
43 "Obtaining a list of all defined classes:"
44 { $subsection classes }
45 "There are several sorts of classes:"
46 { $subsection "builtin-classes" }
47 { $subsection "unions" }
48 { $subsection "intersections" }
49 { $subsection "mixins" }
50 { $subsection "predicates" }
51 { $subsection "singletons" }
52 { $link "tuples" } " are documented in their own section."
53 $nl
54 "Classes can be inspected and operated upon:"
55 { $subsection "class-operations" }
56 { $subsection "class-linearization" }
57 { $see-also "class-index" } ;
58
59 ABOUT: "classes"
60
61 HELP: class
62 { $values { "object" object } { "class" class } }
63 { $description "Outputs an object's canonical class. While an object may be an instance of more than one class, the canonical class is either its built-in class, or if the object is a tuple, its tuple class." }
64 { $class-description "The class of all class words." }
65 { $examples { $example "USING: classes prettyprint ;" "1.0 class ." "float" } { $example "USING: classes prettyprint ;" "IN: scratchpad" "TUPLE: point x y z ;\nT{ point f 1 2 3 } class ." "point" } } ;
66
67 HELP: classes
68 { $values { "seq" "a sequence of class words" } }
69 { $description "Finds all class words in the dictionary." } ;
70
71 HELP: update-map
72 { $var-description "Assoc mapping each class to a set of classes defined in terms of this class. The " { $link define-class } " word uses this information to update generic words when classes are redefined." } ;
73
74 HELP: predicate-word
75 { $values { "word" "a word" } { "predicate" "a predicate word" } }
76 { $description "Suffixes the word's name with \"?\" and creates a word with that name in the same vocabulary as the word itself." } ;
77
78 HELP: define-predicate
79 { $values { "class" class } { "quot" quotation } }
80 { $description "Defines a predicate word for a class." }
81 $low-level-note ;
82
83 HELP: superclass
84 { $values { "class" class } { "super" class } }
85 { $description "Outputs the superclass of a class. All instances of this class are also instances of the superclass." }
86 { $examples 
87     { $example "USING: classes prettyprint ;"
88                "t superclass ."
89                "word"
90     }
91 } ;
92
93 HELP: superclasses
94 { $values
95      { "class" class }
96      { "supers" sequence } }
97 { $description "Outputs a sequence of superclasses of a class along with the class itself." }
98 { $examples 
99     { $example "USING: classes prettyprint ;"
100                "t superclasses ."
101                "{ word t }"
102     }
103 } ;
104
105 { superclass superclasses } related-words
106
107 HELP: members
108 { $values { "class" class } { "seq" "a sequence of union members, or " { $link f } } }
109 { $description "If " { $snippet "class" } " is a union class, outputs a sequence of its member classes, otherwise outputs " { $link f } "." } ;
110
111 HELP: participants
112 { $values { "class" class } { "seq" "a sequence of intersection participants, or " { $link f } } }
113 { $description "If " { $snippet "class" } " is an intersection class, outputs a sequence of its participant classes, otherwise outputs " { $link f } "." } ;
114
115 HELP: define-class
116 { $values { "word" word } { "superclass" class } { "members" "a sequence of class words" } { "participants" "a sequence of class words" } { "metaclass" class } }
117 { $description "Sets a property indicating this word is a class word, thus making it an instance of " { $link class } ", and registers it with " { $link update-map } "." }
118 $low-level-note ;
119
120 HELP: implementors
121 { $values { "class/classes" "a class or a sequence of classes" } { "seq" "a sequence of generic words" } }
122 { $description "Finds all generic words in the dictionary implementing methods for the given set of classes." } ;
123
124 HELP: instance?
125 { $values
126      { "object" object } { "class" class }
127      { "?" "a boolean" } }
128 { $description "Tests whether the input object is a member of the class." } ;