]> gitweb.factorcode.org Git - factor.git/blob - basis/help/help-docs.factor
Fix typo in help for '$values'
[factor.git] / basis / help / help-docs.factor
1 USING: help.markup help.crossref help.stylesheet help.topics
2 help.syntax definitions io prettyprint summary arrays math
3 sequences vocabs strings ;
4 IN: help
5
6 ARTICLE: "printing-elements" "Printing markup elements"
7 "When writing documentation, it is useful to be able to print markup elements for testing purposes. Markup elements which are strings or arrays of elements are printed in the obvious way. Markup elements of the form " { $snippet "{ $directive content... }" } " are printed by executing the " { $snippet "$directive" } " word with the element content on the stack."
8 { $subsection print-element }
9 { $subsection print-content } ;
10
11 ARTICLE: "span-elements" "Span elements"
12 { $subsection $emphasis }
13 { $subsection $strong }
14 { $subsection $link }
15 { $subsection $vocab-link }
16 { $subsection $snippet }
17 { $subsection $slot }
18 { $subsection $url } ;
19
20 ARTICLE: "block-elements" "Block elements"
21 "Paragraph break:"
22 { $subsection $nl }
23 "Standard headings for word documentation:"
24 { $subsection $values }
25 { $subsection $description }
26 { $subsection $class-description }
27 { $subsection $error-description }
28 { $subsection $var-description }
29 { $subsection $contract }
30 { $subsection $examples }
31 { $subsection $warning }
32 { $subsection $notes }
33 { $subsection $side-effects }
34 { $subsection $errors }
35 { $subsection $see-also }
36 "Elements used in " { $link $values } " forms:"
37 { $subsection $instance }
38 { $subsection $maybe }
39 { $subsection $quotation }
40 "Boilerplate paragraphs:"
41 { $subsection $low-level-note }
42 { $subsection $io-error }
43 "Some additional elements:"
44 { $subsection $code }
45 { $subsection $curious }
46 { $subsection $example }
47 { $subsection $heading }
48 { $subsection $links }
49 { $subsection $list }
50 { $subsection $markup-example }
51 { $subsection $references }
52 { $subsection $see }
53 { $subsection $subsection }
54 { $subsection $table } ;
55
56 ARTICLE: "markup-utils" "Markup element utilities"
57 "Utility words to assist in defining new elements:"
58 { $subsection simple-element }
59 { $subsection ($span) }
60 { $subsection ($block) } ;
61
62 ARTICLE: "element-types" "Element types"
63 "Markup elements can be classified into two broad categories, block elements and span elements. Block elements are inset with newlines before and after, whereas span elements flow with the paragraph text."
64 { $subsection "span-elements" }
65 { $subsection "block-elements" }
66 { $subsection "markup-utils" } ;
67
68 IN: help.markup
69 ABOUT: "element-types"
70
71 ARTICLE: "browsing-help" "Browsing documentation"
72 "The easiest way to browse the help is from the help browser tool in the UI, however you can also display help topics in the listener. Help topics are identified by article name strings, or words. You can request a specific help topic:"
73 { $subsection help }
74 "You can also display the main help article for a vocabulary:"
75 { $subsection about } ;
76
77 ARTICLE: "writing-help" "Writing documentation"
78 "By convention, documentation is written in files whose names end with " { $snippet "-docs.factor" } ". Vocabulary documentation should be placed in the same directory as the vocabulary source code; see " { $link "vocabs.loader" } "."
79 $nl
80 "A pair of parsing words are used to define free-standing articles and to associate documentation with words:"
81 { $subsection POSTPONE: ARTICLE: }
82 { $subsection POSTPONE: HELP: }
83 "A parsing word defines the main help article for a vocabulary:"
84 { $subsection POSTPONE: ABOUT: }
85 "The " { $emphasis "content" } " in both cases is a " { $emphasis "markup element" } ", a recursive structure taking one of the following forms:"
86 { $list
87     { "a string," }
88     { "an array of markup elements," }
89     { "or an array of the form " { $snippet "{ $directive content... }" } ", where " { $snippet "$directive" } " is a markup word whose name starts with " { $snippet "$" } ", and " { $snippet "content..." } " is a series of markup elements" }
90 }
91 { $subsection "element-types" }
92 { $subsection "printing-elements" }
93 "Related words can be cross-referenced:"
94 { $subsection related-words }
95 { $see-also "help.lint" } ;
96
97 ARTICLE: "help-impl" "Help system implementation"
98 "Help topic protocol:"
99 { $subsection article-name }
100 { $subsection article-title }
101 { $subsection article-content }
102 { $subsection article-parent }
103 { $subsection set-article-parent }
104 "Boilerplate word help can be automatically generated (for example, slot accessor help):"
105 { $subsection word-help }
106 { $subsection word-help* }
107 "Help article implementation:"
108 { $subsection article }
109 { $subsection articles }
110 "Links:"
111 { $subsection link }
112 { $subsection >link }
113 "Utilities for traversing markup element trees:"
114 { $subsection elements }
115 { $subsection collect-elements }
116 "Links and " { $link article } " instances implement the definition protocol; refer to " { $link "definitions" } "." ;
117
118 ARTICLE: "help" "Help system"
119 "The help system maintains documentation written in a simple markup language, along with cross-referencing and search. Documentation can either exist as free-standing " { $emphasis "articles" } " or be associated with words."
120 { $subsection "browsing-help" }
121 { $subsection "writing-help" }
122 { $vocab-subsection "Help lint tool" "help.lint" }
123 { $subsection "help-impl" } ;
124
125 IN: help
126 ABOUT: "help"
127
128 HELP: $title
129 { $values { "topic" "a help article name or a word" } }
130 { $description "Prints a help article's title, or a word's " { $link summary } ", depending on the type of " { $snippet "topic" } "." } ;
131
132 HELP: print-topic
133 { $values { "topic" "an article name or a word" } }
134 { $description
135     "Displays a help topic on " { $link output-stream } "."
136 } ;
137
138 HELP: help
139 { $values { "topic" "an article name or a word" } }
140 { $description
141     "Displays a help topic."
142 } ;
143 HELP: about
144 { $values { "vocab" "a vocabulary specifier" } }
145 { $description
146     "Displays the main help article for the vocabulary. The main help article is set with the " { $link POSTPONE: ABOUT: } " parsing word."
147 } ;
148
149 HELP: :help
150 { $description "Displays documentation for the most recent error." } ;
151
152 HELP: $subsection
153 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
154 { $description "Prints a large clickable link to the help topic named by the first string element of " { $snippet "element" } "." }
155 { $examples
156     { $code "{ $subsection \"sequences\" }" }
157 } ;
158
159 HELP: $index
160 { $values { "element" "a markup element containing one quotation with stack effect " { $snippet "( quot -- )" } } }
161 { $description "Calls the quotation to generate a sequence of help topics, and outputs a " { $link $subsection } " for each one." } ;
162
163 HELP: ($index)
164 { $values { "articles" "a sequence of help articles" } }
165 { $description "Writes a list of " { $link $subsection } " elements to " { $link output-stream } "." } ;
166
167 HELP: xref-help
168 { $description "Update help cross-referencing. Usually this is done automatically." } ;
169
170 HELP: sort-articles
171 { $values { "seq" "a sequence of help topics" } { "newseq" "a sequence of help topics" } }
172 { $description "Sorts a sequence of help topics." } ;
173
174 { article-children article-parent xref-help } related-words
175
176 HELP: $predicate
177 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
178 { $description "Prints the boilerplate description of a class membership predicate word such as " { $link array? } " or " { $link integer? } "." } ;
179
180 HELP: print-element
181 { $values { "element" "a markup element" } }
182 { $description "Prints a markup element to " { $link output-stream } "." } ;
183
184 HELP: print-content
185 { $values { "element" "a markup element" } }
186 { $description "Prints a top-level markup element to " { $link output-stream } "." } ;
187
188 HELP: simple-element
189 { $class-description "Class of simple elements, which are just arrays of elements." } ;
190
191 HELP: ($span)
192 { $values { "quot" "a quotation" } }
193 { $description "Prints an inline markup element." } ;
194
195 HELP: ($block)
196 { $values { "quot" "a quotation" } }
197 { $description "Prints a block markup element with newlines before and after." } ;
198
199 HELP: $heading
200 { $values { "element" "a markup element" } }
201 { $description "Prints a markup element, usually a string, as a block with the " { $link heading-style } "." }
202 { $examples
203     { $markup-example { $heading "What remains to be discovered" } }
204 } ;
205
206 HELP: $subheading
207 { $values { "element" "a markup element of the form " { $snippet "{ title content }" } } }
208 { $description "Prints a markup element, usually a string, as a block with the " { $link strong-style } "." }
209 { $examples
210     { $markup-example { $subheading "Developers, developers, developers!" } }
211 } ;
212
213 HELP: $code
214 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
215 { $description "Prints code examples, as seen in many help articles. The markup element must be an array of strings." }
216 { $notes
217     "The code becomes clickable if the output stream supports it, and clicking it opens a listener window with the text inserted at the input prompt."
218     $nl
219     "If you want to show code along with sample output, use the " { $link $example } " element."
220 }
221 { $examples
222     { $markup-example { $code "2 2 + ." } }
223 } ;
224
225 HELP: $nl
226 { $values { "children" "unused parameter" } }
227 { $description "Prints a paragraph break. The parameter is unused." } ;
228
229 HELP: $snippet
230 { $values { "children" "markup elements" } }
231 { $description "Prints a key word or otherwise notable snippet of text, such as a type or a word input parameter. To document slot names, use " { $link $slot } "." } ;
232
233 HELP: $slot
234 { $values { "children" "markup elements" } }
235 { $description "Prints a tuple slot name in the same way as a snippet. The help tool can check that there exists an accessor with this name." } ;
236
237 HELP: $vocabulary
238 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
239 { $description "Prints a word's vocabulary. This markup element is automatically output by the help system, so help descriptions of parsing words should not call it." } ;
240
241 HELP: $description
242 { $values { "element" "a markup element" } }
243 { $description "Prints the description subheading found on the help page of most words." } ;
244
245 HELP: $contract
246 { $values { "element" "a markup element" } }
247 { $description "Prints a heading followed by a contract, found on the help page of generic words. Every generic word should document a contract which specifies method behavior that callers can rely upon, and implementations must obey." }
248 { $examples
249     { $markup-example { $contract "Methods of this generic word must always crash." } }
250 } ;
251
252 HELP: $examples
253 { $values { "element" "a markup element" } }
254 { $description "Prints a heading followed by some examples. Word documentation should include examples, at least if the usage of the word is not entirely obvious." }
255 { $examples
256     { $markup-example { $examples { $example "USING: math prettyprint ;" "2 2 + ." "4" } } }
257 } ;
258
259 HELP: $example
260 { $values { "element" "a markup element of the form " { $snippet "{ inputs... output }" } } }
261 { $description "Prints a clickable example with sample output. The markup element must be an array of strings. All but the last string are joined by newlines and taken as the input text, and the last string is the output. The example becomes clickable if the output stream supports it, and clicking it opens a listener window with the input text inserted at the input prompt." }
262 { $examples
263     "The input text must contain a correct " { $link POSTPONE: USING: } " declaration, and output text should be a string of what the input prints when executed, not the final stack contents or anything like that. So the following is an incorrect example:"
264     { $markup-example { $unchecked-example "2 2 +" "4" } }
265     "However the following is right:"
266     { $markup-example { $example "USING: math prettyprint ;" "2 2 + ." "4" } }
267     "Examples can incorporate a call to " { $link .s } " to show multiple output values; the convention is that you may assume the stack is empty before the example evaluates."
268 } ;
269
270 HELP: $markup-example
271 { $values { "element" "a markup element" } }
272 { $description "Prints a clickable example showing the prettyprinted source text of " { $snippet "element" } " followed by rendered output. The example becomes clickable if the output stream supports it." }
273 { $examples
274     { $markup-example { $markup-example { $emphasis "Hi" } } }
275 } ;
276
277 HELP: $warning
278 { $values { "element" "a markup element" } }
279 { $description "Prints an element inset in a block styled as so to draw the reader's attention towards it." }
280 { $examples
281     { $markup-example { $warning "Incorrect use of this product may cause serious injury or death." } }
282 } ;
283
284 HELP: $link
285 { $values { "element" "a markup element of the form " { $snippet "{ topic }" } } }
286 { $description "Prints a link to a help article or word." }
287 { $examples
288     { $markup-example { $link "dlists" } }
289     { $markup-example { $link + } }
290 } ;
291
292 HELP: textual-list
293 { $values { "seq" "a sequence" } { "quot" { $quotation "( elt -- )" } } }
294 { $description "Applies the quotation to each element of the sequence, printing a comma between each pair of elements." }
295 { $examples
296     { $example "USING: help.markup io ;" "{ \"fish\" \"chips\" \"salt\" } [ write ] textual-list" "fish, chips, salt" }
297 } ;
298
299 HELP: $links
300 { $values { "topics" "a sequence of article names or words" } }
301 { $description "Prints a series of links to help articles or word documentation." }
302 { $notes "This markup element is used to implement " { $link $links } "." }
303 { $examples
304     { $markup-example { $links + - * / } }
305 } ;
306
307 HELP: $see-also
308 { $values { "topics" "a sequence of article names or words" } }
309 { $description "Prints a heading followed by a series of links." }
310 { $examples
311     { $markup-example { $see-also "graphs" "dlists" } }
312 } ;
313
314 { $see-also $related related-words } related-words
315
316 HELP: $table
317 { $values { "element" "an array of arrays of markup elements" } }
318 { $description "Prints a table given as an array of rows, where each row must have the same number of columns." }
319 { $examples
320     { $markup-example
321         { $table
322             { "a" "b" "c" }
323             { "d" "e" "f" }
324         }
325     }
326 } ;
327
328 HELP: $values
329 { $values { "element" "an array of pairs of markup elements" } }
330 { $description "Prints the description of arguments and values found on every word help page. The first element of a pair is the argument name and is output with " { $link $snippet } ". The remainder is either a single class word, or an element. If it is a class word " { $snippet "class" } ", it is inserted as if it were shorthand for " { $snippet "{ $instance class }" } "." }
331 { $see-also $maybe $instance $quotation } ;
332
333 HELP: $instance
334 { $values { "element" "an array with shape " { $snippet "{ class }" } } }
335 { $description
336     "Produces the text ``a " { $emphasis "class" } "'' or ``an " { $emphasis "class" } "'', depending on the first letter of " { $emphasis "class" } "."
337 }
338 { $examples
339     { $markup-example { $instance string } }
340     { $markup-example { $instance integer } }
341     { $markup-example { $instance f } }
342 } ;
343
344 HELP: $maybe
345 { $values { "element" "an array with shape " { $snippet "{ class }" } } }
346 { $description
347     "Produces the text ``a " { $emphasis "class" } " or f'' or ``an " { $emphasis "class" } " or f'', depending on the first letter of " { $emphasis "class" } "."
348 }
349 { $examples
350     { $markup-example { $maybe string } }
351 } ;
352
353 HELP: $quotation
354 { $values { "element" "an array with shape " { $snippet "{ effect }" } } }
355 { $description
356     "Produces the text ``a quotation with stack effect " { $emphasis "effect" } "''."
357 }
358 { $examples
359     { $markup-example { $quotation "( obj -- )" } }
360 } ;
361
362 HELP: $list
363 { $values { "element" "an array of markup elements" } }
364 { $description "Prints a bulleted list of markup elements." }
365 { $notes
366     "A common mistake is that if an item consists of more than just a string, it will be broken up as several items:"
367     { $markup-example
368         { $list
369             "First item"
370             "Second item " { $emphasis "with emphasis" }
371         }
372     }
373     "The fix is easy; just group the two markup elements making up the second item into one markup element:"
374     { $markup-example
375         { $list
376             "First item"
377             { "Second item " { $emphasis "with emphasis" } }
378         }
379     }
380 } ;
381
382 HELP: $errors
383 { $values { "element" "a markup element" } }
384 { $description "Prints the errors subheading found on the help page of some words. This section should document any errors thrown by the word." }
385 { $examples
386     { $markup-example { $errors "I/O errors, network errors, hardware errors... oh my!" } }
387 } ;
388
389 HELP: $side-effects
390 { $values { "element" "a markup element of the form " { $snippet "{ string... }" } } }
391 { $description "Prints a heading followed by a list of input values or variables which are modified by the word being documented." }
392 { $examples
393     { $markup-example
394         { { $values { "seq" "a mutable sequence" } } { $side-effects "seq" } }
395     }
396 } ;
397
398 HELP: $notes
399 { $values { "element" "a markup element" } }
400 { $description "Prints the notes subheading found on the help page of some words. This section should document usage tips and pitfalls." } ;
401
402 HELP: $see
403 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
404 { $description "Prints the definition of " { $snippet "word" } " by calling " { $link see } "." }
405 { $examples
406     { $markup-example { "Here is a word definition:" { $see reverse } } }
407 } ;
408
409 HELP: $definition
410 { $values { "element" "a markup element of the form " { $snippet "{ word }" } } }
411 { $description "Prints a heading followed by the definition of " { $snippet "word" } " by calling " { $link see } "." } ;
412
413 HELP: $curious
414 { $values { "element" "a markup element" } }
415 { $description "Prints a heading followed by a markup element." }
416 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
417
418 HELP: $references
419 { $values { "element" "a markup element of the form " { $snippet "{ topic... }" } } }
420 { $description "Prints a heading followed by a series of links." }
421 { $notes "This element type is used by the cookbook-style introductory articles in the " { $link "handbook" } "." } ;
422
423 HELP: HELP:
424 { $syntax "HELP: word content... ;" }
425 { $values { "word" "a word" } { "content" "markup elements" } }
426 { $description "Defines documentation for a word." }
427 { $examples
428     { $code
429         ": foo 2 + ;"
430         "HELP: foo"
431         "{ $values { \"m\" \"an integer\" } { \"n\" \"an integer\" } }"
432         "{ $description \"Increments a value by 2.\" } ;"
433         "\\ foo help"
434     }
435 } ;
436
437 HELP: ARTICLE:
438 { $syntax "ARTICLE: topic title content... ;" }
439 { $values { "topic" "an object" } { "title" "a string" } { "content" "markup elements" } }
440 { $description "Defines a help article. String topic names are reserved for core documentation. Contributed modules should name articles by arrays, where the first element of an array identifies the module; for example, " { $snippet "{ \"httpd\" \"intro\" }" } "." }
441 { $examples
442     { $code
443         "ARTICLE: \"example\" \"An example article\""
444         "\"Hello world.\" ;"
445     }
446 } ;
447
448 HELP: ABOUT:
449 { $syntax "ABOUT: article" }
450 { $values { "article" "a help article" } }
451 { $description "Defines the main documentation article for the current vocabulary." } ;
452
453 HELP: vocab-help
454 { $values { "vocab-spec" "a vocabulary specifier" } { "help" "a help article" } }
455 { $description "Outputs the main help article for a vocabulary. The main help article can be set with " { $link POSTPONE: ABOUT:  } "." } ;