classes.maybe-docs: create some documentation for the maybe vocab

Integrate the pointers to the new article into existing help system,
primarily by looking for the uses of the "unions" article.
char-rename
Alexander Iljin 2017-03-16 13:24:28 +03:00 committed by John Benediktsson
parent bad5408c76
commit b1a24358f3
7 changed files with 27 additions and 5 deletions

View File

@ -54,6 +54,7 @@ $nl
"builtin-classes"
"unions"
"intersections"
"maybes"
"mixins"
"predicates"
"singletons"

View File

@ -0,0 +1,19 @@
! Copyright (C) 2017 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel ;
IN: classes.maybe
ABOUT: "maybes"
ARTICLE: "maybes" "Maybe classes"
"A " { $snippet "maybe" } " is an anonymous union class (" { $link "unions" } ") of its members and the " { $link POSTPONE: f } " class. An object is an instance of a " { $snippet "maybe" } " class if it is either an instance of any of its participants, or " { $link POSTPONE: f } "." $nl
"The " { $snippet "maybe" } " classes are used to declare typed slots that are optional for a tuple. Without this mechanism it would be an error to assign " { $link POSTPONE: f } " to such a typed slot, and therefore any tuple containing them without specifying an " { $link POSTPONE: initial: } " value could not be created with the word " { $link new } "." $nl
"A slot with an empty " { $snippet "maybe{ }" } " class can only hold the " { $link POSTPONE: f } " value."
{ $examples
{ $example
"TUPLE: test-maybe { value maybe{ fixnum string } } ;"
"test-maybe new value>>"
"f"
}
}
{ $see-also "unions" POSTPONE: maybe{ } ;

View File

@ -0,0 +1 @@
Maybe classes

View File

@ -16,7 +16,7 @@ ARTICLE: "mixins" "Mixin classes"
mixin-class?
}
"Mixins are used to defines suites of behavior which are generally useful and can be applied to user-defined classes. For example, the " { $link immutable-sequence } " mixin can be used with user-defined sequences to make them immutable."
{ $see-also "unions" "tuple-subclassing" } ;
{ $see-also "unions" "maybes" "tuple-subclassing" } ;
HELP: mixin-class
{ $class-description "The class of mixin classes." } ;

View File

@ -16,7 +16,8 @@ ARTICLE: "slot-class-declaration" "Slot class declarations"
{ "The " { $link slots>tuple } " and " { $link >tuple } " words ensure that the values in the sequence satisfy the correct class predicates." }
{ { $link "tuple-redefinition" } " fills in new slots with initial values and ensures that changes to existing declarations result in incompatible values being replaced with the initial value of their respective slots." }
}
{ $subsections "slot-class-coercion" } ;
{ $subsections "slot-class-coercion" }
"The " { $link "maybes" } " are a useful way to specify class for an optional slot." ;
ARTICLE: "slot-class-coercion" "Coercive slot declarations"
"If the class of a slot is declared to be one of " { $link fixnum } " or " { $link float } ", then rather than testing values with the class predicate, writer words coerce values to the relevant type with " { $link >fixnum } " or " { $link >float } ". This may still result in error, but permits a wider range of values than a class predicate test. It also results in a possible loss of precision; for example, storing a large integer into a " { $link fixnum } " slot will silently overflow and discard high bits, and storing a ratio into a " { $link float } " slot may lose precision if the ratio is one which cannot be represented exactly with floating-point."
@ -192,7 +193,7 @@ $nl
}
"Declaring a tuple class final prohibits other classes from subclassing it:"
{ $subsections POSTPONE: final }
{ $see-also "call-next-method" "parameterized-constructors" "unions" "mixins" } ;
{ $see-also "call-next-method" "parameterized-constructors" "unions" "mixins" "maybes" } ;
ARTICLE: "tuple-introspection" "Tuple introspection"
"In addition to the slot reader and writer words which " { $link POSTPONE: TUPLE: } " defines for every tuple class, it is possible to construct and take apart entire tuples in a generic way."

View File

@ -16,7 +16,7 @@ ARTICLE: "unions" "Union classes"
union-class?
}
"Unions are used to define behavior shared between a fixed set of classes, as well as to conveniently define predicates."
{ $see-also "mixins" "tuple-subclassing" } ;
{ $see-also "mixins" "maybes" "tuple-subclassing" } ;
ABOUT: "unions"

View File

@ -173,7 +173,7 @@ $nl
{ { { $snippet "\"superclass\"" } ", " { $snippet "\"predicate-definition\"" } } { $link "predicates" } }
{ { $snippet "\"members\"" } { $link "unions" } }
{ { $snippet "\"members\"" } { $link "unions" } { $link "maybes" } }
{ { $snippet "\"slots\"" } { $link "slots" } }