PageRenderTime 30ms CodeModel.GetById 8ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/core/classes/classes-docs.factor

http://github.com/abeaumont/factor
Unknown | 168 lines | 147 code | 21 blank | 0 comment | 0 complexity | e03ce24a019e3b14dea4c37ada36a128 MD5 | raw file
  1USING: help.markup help.syntax kernel kernel.private
  2namespaces sequences words arrays effects math
  3classes.private classes.union classes.mixin
  4classes.predicate quotations ;
  5IN: classes
  6
  7ARTICLE: "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{ $subsections
 19    predicate
 20    predicate?
 21}
 22"A predicate word holds a reference to the class it is predicating over in the " { $snippet "\"predicating\"" } " word property." $nl
 23"Implementation of class reloading:"
 24{ $subsections reset-class forget-class forget-methods } ;
 25
 26ARTICLE: "classes" "Classes"
 27"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."
 28$nl
 29"At the implementation level, a class is a word with certain word properties set."
 30$nl
 31"Words for working with classes are found in the " { $vocab-link "classes" } " vocabulary."
 32$nl
 33"Classes themselves form a class:"
 34{ $subsections class? }
 35"You can ask an object for its class:"
 36{ $subsections class-of }
 37"Testing if an object is an instance of a class:"
 38{ $subsections instance? }
 39"You can ask a class for its superclass:"
 40{ $subsections
 41    superclass
 42    superclasses
 43    subclass-of?
 44}
 45"Class predicates can be used to test instances directly:"
 46{ $subsections "class-predicates" }
 47"There is a universal class which all objects are an instance of, and an empty class with no instances:"
 48{ $subsections
 49    object
 50    null
 51}
 52"Obtaining a list of all defined classes:"
 53{ $subsections classes }
 54"There are several sorts of classes:"
 55{ $subsections
 56    "builtin-classes"
 57    "unions"
 58    "intersections"
 59    "mixins"
 60    "predicates"
 61    "singletons"
 62}
 63{ $link "tuples" } " are documented in their own section."
 64$nl
 65"Classes can be inspected and operated upon:"
 66{ $subsections
 67    "class-operations"
 68    "class-linearization"
 69}
 70{ $see-also "class-index" } ;
 71
 72ABOUT: "classes"
 73
 74HELP: class-of
 75{ $values { "object" object } { "class" class } }
 76{ $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." }
 77{ $class-description "The class of all class words." }
 78{ $examples { $example "USING: classes prettyprint ;" "1.0 class-of ." "float" } { $example "USING: classes prettyprint ;" "IN: scratchpad" "TUPLE: point x y z ;\nT{ point f 1 2 3 } class-of ." "point" } } ;
 79
 80HELP: classes
 81{ $values { "seq" "a sequence of class words" } }
 82{ $description "Finds all class words in the dictionary." } ;
 83
 84HELP: update-map
 85{ $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." } ;
 86
 87HELP: predicate-word
 88{ $values { "word" "a word" } { "predicate" "a predicate word" } }
 89{ $description "Suffixes the word's name with \"?\" and creates a word with that name in the same vocabulary as the word itself." } ;
 90
 91HELP: define-predicate
 92{ $values { "class" class } { "quot" quotation } }
 93{ $description "Defines a predicate word for a class." }
 94$low-level-note ;
 95
 96HELP: superclass
 97{ $values { "class" class } { "super" class } }
 98{ $description "Outputs the superclass of a class. All instances of this class are also instances of the superclass." }
 99{ $examples
100    { $example "USING: classes prettyprint ;"
101               "t superclass ."
102               "word"
103    }
104} ;
105
106HELP: superclasses
107{ $values
108     { "class" class }
109     { "supers" sequence } }
110{ $description "Outputs a sequence of superclasses of a class along with the class itself." }
111{ $examples
112    { $example "USING: classes prettyprint ;"
113               "t superclasses ."
114               "{ word t }"
115    }
116} ;
117
118HELP: subclass-of?
119{ $values
120    { "class" class }
121    { "superclass" class }
122    { "?" boolean }
123}
124{ $description "Outputs a boolean value indicating whether " { $snippet "class" } " is at any level a subclass of " { $snippet "superclass" } "." }
125{ $examples
126    { $example "USING: classes classes.tuple prettyprint words ;"
127               "tuple-class \\ class subclass-of? ."
128               "t"
129    }
130} ;
131
132{ superclass superclasses subclass-of? } related-words
133
134HELP: members
135{ $values { "class" class } { "seq" "a sequence of union members, or " { $link f } } }
136{ $description "If " { $snippet "class" } " is a union class, outputs a sequence of its member classes, otherwise outputs " { $link f } "." } ;
137
138HELP: participants
139{ $values { "class" class } { "seq" "a sequence of intersection participants, or " { $link f } } }
140{ $description "If " { $snippet "class" } " is an intersection class, outputs a sequence of its participant classes, otherwise outputs " { $link f } "." } ;
141
142HELP: define-class
143{ $values { "word" word } { "superclass" class } { "members" "a sequence of class words" } { "participants" "a sequence of class words" } { "metaclass" class } }
144{ $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 } "." }
145$low-level-note ;
146
147HELP: implementors
148{ $values { "class/classes" "a class or a sequence of classes" } { "seq" "a sequence of generic words" } }
149{ $description "Finds all generic words in the dictionary implementing methods for the given set of classes." } ;
150
151HELP: instance?
152{ $values
153     { "object" object } { "class" class }
154     { "?" "a boolean" } }
155{ $description "Tests whether the input object is a member of the class." } ;
156
157HELP: reset-class
158{ $values { "class" class } }
159{ $description "Forgets all of words that the class defines, but not words that are defined on the class. For instance, on a tuple class, this word should reset all of the tuple accessors but not things like " { $link nth } " that may be defined on the class elsewhere." } ;
160
161HELP: forget-class
162{ $values { "class" class } }
163{ $description "Removes a class by forgetting all of the methods defined on that class and all of the methods generated when that class was defined. Also resets any caches that may contain that class." } ;
164
165HELP: forget-methods
166{ $values { "class" class } }
167{ $description "Forgets all methods defined on a class. In contrast to " { $link reset-class } ", this not only forgets accessors but also any methods at all on the class." } ;
168