]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/variants/variants-docs.factor
ui.listener: document that ~/.factor-history persists input history
[factor.git] / extra / variants / variants-docs.factor
index f9b62e11f30c8f5a882b976e0a031f69aee6cd63..f0dc26baa2db3734938baf10ff12db1d986c06d2 100644 (file)
@@ -1,10 +1,11 @@
-! (c)2009 Joe Groff bsd license
+! Copyright (C) 2009 Joe Groff.
+! See https://factorcode.org/license.txt for BSD license.
 USING: arrays classes classes.singleton classes.tuple help.markup
 help.syntax kernel multiline slots quotations ;
 IN: variants
 
 HELP: VARIANT:
-{ $syntax <"
+{ $syntax "
 VARIANT: class-name
     singleton
     singleton
@@ -12,9 +13,9 @@ VARIANT: class-name
     .
     .
     .
-    ; "> }
-{ $description "Defines " { $snippet "class-name" } " as a union of the following " { $link singleton-class } " and " { $link tuple-class } " definitions. Each " { $snippet "singleton" } " word is defined as a " { $snippet "singleton-class" } ", and each " { $snippet "tuple" } " word is defined aas a " { $snippet "tuple-class" } " with the given set of " { $snippet "slot" } "s, using the same syntax for slot specifiers as " { $link POSTPONE: TUPLE: } ". Typed tuple slots can recursively reference the variant " { $snippet "class-name" } " being defined. For " { $snippet "tuple" } " types, a " { $link boa } " constructor word " { $snippet "<tuple>" } " is defined as well." }
-{ $examples { $code <"
+    ; " }
+{ $description "Defines " { $snippet "class-name" } " as a union of the following " { $link singleton-class } " and " { $link tuple-class } " definitions. Each " { $snippet "singleton" } " word is defined as a " { $snippet "singleton-class" } ", and each " { $snippet "tuple" } " word is defined as a " { $snippet "tuple-class" } " with the given set of " { $snippet "slot" } "s, using the same syntax for slot specifiers as " { $link POSTPONE: TUPLE: } ". Typed tuple slots can recursively reference the variant " { $snippet "class-name" } " being defined. For " { $snippet "tuple" } " types, a " { $link boa } " constructor word " { $snippet "<tuple>" } " is defined as well." }
+{ $examples { $code "
 USING: kernel variants ;
 IN: scratchpad
 
@@ -22,12 +23,24 @@ VARIANT: list
     nil
     cons: { { first object } { rest list } }
     ;
-"> } } ;
+" } } ;
+
+HELP: VARIANT-MEMBER:
+{ $description "Defines a new member of a variant class without restricting such definitions to a single statement or source file. The variant class should be listed first, and the class member should follow." }
+{ $examples { $code "
+USING: kernel variants ;
+IN: scratchpad
+
+VARIANT: list ;
+
+VARIANT-MEMBER: list nil ;
+VARIANT-MEMBER: list cons: { { first object } { rest list } } ;
+" } } ;
 
 HELP: match
 { $values { "branches" array } }
 { $description "Dispatches on the type of the value on the top of the stack. If the type is a " { $link singleton-class } ", the corresponding quotation is called with the underlying stack unchanged. If the type is a " { $link tuple-class } ", the tuple slots are pushed onto the stack by order of arguments." }
-{ $examples { $example <"
+{ $examples { $example "
 USING: kernel math prettyprint variants ;
 IN: scratchpad
 
@@ -43,7 +56,7 @@ VARIANT: list
     } match ;
 
 1 2 3 4 nil <cons> <cons> <cons> <cons> list-length .
-"> "4" } } ;
+" "4" } } ;
 
 HELP: unboa
 { $values { "class" class } }
@@ -56,8 +69,11 @@ HELP: variant-class
 
 ARTICLE: "variants" "Algebraic data types"
 "The " { $vocab-link "variants" } " vocabulary provides syntax and combinators for defining and manipulating algebraic data types."
-{ $subsection POSTPONE: VARIANT: }
-{ $subsection variant-class }
-{ $subsection match } ;
+{ $subsections
+    POSTPONE: VARIANT:
+    POSTPONE: VARIANT-MEMBER:
+    variant-class
+    match
+} ;
 
 ABOUT: "variants"