]> gitweb.factorcode.org Git - factor.git/commitdiff
documentation updates
authorSlava Pestov <slava@factorcode.org>
Thu, 19 Jan 2006 23:15:37 +0000 (23:15 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 19 Jan 2006 23:15:37 +0000 (23:15 +0000)
doc/handbook/collections.facts
doc/handbook/handbook.facts
doc/handbook/prettyprinter.facts [new file with mode: 0644]
library/bootstrap/boot-stage1.factor
library/syntax/prettyprint.facts

index dc3ae2d8731d2d12dbfae6b9c9280b0dd721b6a9..faa99ff71adb70182a99f1d0becb62cb2b1db61f 100644 (file)
@@ -1,13 +1,17 @@
-USING: hashtables hashtables-internals help kernel namespaces
-queues ;
+USING: hashtables hashtables-internals help io-internals kernel
+namespaces queues ;
 
 GLOSSARY: "collection" "an object whose primary purpose is to aggregate other objects; examples include sequences, queues and hashtables" ;
 
 ARTICLE: "collections" "Collections"
+"Classical data structures:"
 { $subsection "sequences" }
 { $subsection "queues" }
 { $subsection "hashtables" }
-{ $subsection "namespaces" } ;
+"An abstraction on hashtables:"
+{ $subsection "namespaces" }
+"A low-level facility:"
+{ $subsection "buffers" } ;
 
 ARTICLE: "queues" "Queues"
 "A simple last-in-first-out queue data structure."
@@ -142,3 +146,27 @@ ARTICLE: "namespaces-internals" "Namespace implementation details"
 "A pair of words push and pop namespaces on the namestack."
 { $subsection >n }
 { $subsection n> } ;
+
+ARTICLE: "buffers" "Locked I/O buffers"
+"I/O buffers are a circular ring structure, a fixed-size queue of characters. Their key feature is that they are backed by manually allocated storage that does not get moved by the garbage collector. They are typically used for asynchronous I/O in conjunction with the C library interface in Factor's implementation."
+$terpri
+"Buffer words are in the " { $snippet "io-internals" } " vocabulary."
+{ $subsection buffer }
+{ $subsection <buffer> }
+"Buffers must be manually deallocated:"
+{ $subsection buffer-free }
+"Buffer operations:"
+{ $subsection buffer-reset }
+{ $subsection buffer-length }
+{ $subsection buffer-empty? }
+{ $subsection buffer-capacity }
+"Reading from the buffer:"
+{ $subsection buffer-peek }
+{ $subsection buffer-pop }
+{ $subsection buffer> }
+{ $subsection buffer>> }
+{ $subsection buffer-contents }
+"Writing to the buffer:"
+{ $subsection buffer-extend }
+{ $subsection ch>buffer }
+{ $subsection >buffer } ;
index 923f764f1898c7c9c0f12d24189eaa9e3cb1286b..e4326a68a9091cb5b1ff0b65e8feb115ee41a35a 100644 (file)
@@ -7,7 +7,7 @@ $terpri
 { $subsection "presentation-intro" }
 { $subsection "tutorial" }
 { $subsection "quickref" }
-"More detailed reference documentation:"
+"Detailed reference documentation:"
 { $subsection "syntax" }
 { $subsection "dataflow" }
 { $subsection "words" }
@@ -15,7 +15,9 @@ $terpri
 { $subsection "math" }
 { $subsection "collections" }
 { $subsection "streams" }
-{ $subsection "parser" } ;
+{ $subsection "parser" }
+{ $subsection "prettyprint" }
+;
 
 ARTICLE: "presentation-intro" "The presentation-based UI"
 "Factor provides a " { $emphasis "presentation-based" } " user interface. A " { $emphasis "presentation" } " is a graphical representation of a live object. You can see presentations everywhere; help links, words, and code examples are all presentations."
diff --git a/doc/handbook/prettyprinter.facts b/doc/handbook/prettyprinter.facts
new file mode 100644 (file)
index 0000000..ce95676
--- /dev/null
@@ -0,0 +1,65 @@
+USING: help io prettyprint ;
+
+GLOSSARY: "prettyprinter" "a set of words for printing objects in readable form" ;
+
+ARTICLE: "prettyprint" "The prettyprinter"
+"One of Factor's key features is the ability to print almost any object as a valid source literal expression. This greatly aids debugging and provides the building blocks for light-weight object serialization facilities."
+$terpri
+"Prettyprinter words are found in the " { $snippet "prettyprint" } " vocabulary."
+$terpri
+"The key words to print an object to the " { $link stdio } " stream; the first two emit a trailing newline, the second two do not:"
+{ $subsection . }
+{ $subsection short. }
+{ $subsection pprint }
+{ $subsection pprint-short }
+"The string representation of an object can be requested:"
+{ $subsection unparse }
+{ $subsection unparse-short }
+"The prettyprinter is flexible and extensible."
+{ $subsection "prettyprint-limitations" }
+{ $subsection "prettyprint-variables" }
+{ $subsection "prettyprint-extension" }
+;
+
+ARTICLE: "prettyprint-limitations" "Prettyprinter limitations"
+"The prettyprinter has some limitations; namely, the following objects may not print in a readable form:"
+{ $list
+    { "When printing words, no " { $link POSTPONE: USE: } " declarations are output, hence the result may not be immediately readable without prefixing appropriate declarations." }
+    "Shared structure is not reflected in the printed output; if the output is parsed back in, fresh objects are created for all literal denotations."
+    { "Circular structure is not printed in a readable way. Circular references print as " { $snippet "#" } "." }
+    "Floating point numbers might not equal themselves after being printed and read, since a decimal representation of a float is inexact."
+}
+"On a final note, the " { $link short. } ", " { $link pprint-short } " and " { $link unparse-short } " words restrict the length and nesting of printed sequences, their output will very likely not be valid syntax. They are only intended for interactive use." ;
+
+ARTICLE: "prettyprint-variables" "Prettyprint control variables"
+"The following variables affect the " { $link . } " and " { $link pprint } " words if set in the current dynamic scope:"
+{ $subsection tab-size }
+{ $subsection margin }
+{ $subsection nesting-limit }
+{ $subsection length-limit }
+{ $subsection line-limit }
+{ $subsection string-limit }
+"Note that the " { $link short. } " and " { $link pprint-short } " variables override some of these variables."
+{
+    $warning "Treat the global variables as essentially being constants. Only ever rebind them in a nested scope."
+    $terpri
+    "Some of the globals are safe to change, like the tab size and wrap margin. However setting limits globally could break code which uses the prettyprinter as a serialization mechanism."
+} ;
+
+ARTICLE: "prettyprint-extension" "Extending the prettyprinter"
+"It is possible to define literal syntax for a new class using the " { $link "parser" } ", and then define a corresponding prettyprint method for the class which reproduces the literal syntax."
+$terpri
+"The prettyprinter maintains some internal state while prettyprinting. First, the object graph is traversed and a tree of " { $emphasis "sections" } " is produced. A section is either a text node or a " { $emphasis "block" } " which itself consists of sections."
+$terpri
+"Once the output is divided into sections, the tree is traversed and intelligent decisions are made about indentation and line breaks. If a block does not fit on the remainder of the current line, a newline is output before and after the block, and additional indentation is used when printing the block."
+$terpri
+"The following generic word is called to output a prettyprinting section for an object:"
+{ $subsection pprint* }
+"Two types of leaf sections:"
+{ $subsection text }
+{ $subsection newline }
+"Nesting and denesting is done using three words. There are two words to denest a block; they vary in indentation policy:"
+{ $subsection <block }
+{ $subsection block> }
+{ $subsection block; }
+"Recall that since " { $link text } " sections take style hashtables as input, any type of formatted text can be output, including presentations. See " { $link "styles" } " to explore the possibility." ;
index 85c1da696c6e2320ad6cb1bfb9e7998c4bc57ae1..90a0e95818e6f0bd2c2984c0c602383c14291da1 100644 (file)
@@ -266,6 +266,7 @@ vectors words ;
         "/doc/handbook/math.facts"
         "/doc/handbook/objects.facts"
         "/doc/handbook/parser.facts"
+        "/doc/handbook/prettyprinter.facts"
         "/doc/handbook/sequences.facts"
         "/doc/handbook/streams.facts"
         "/doc/handbook/syntax.facts"
index b28fbc32c7a9ca121a6be21855ce0cc37a648247..780b5d4604a78bcf27b4c9e6a268e488719fbacb 100644 (file)
@@ -1,9 +1,9 @@
-USING: help prettyprint words ;
+USING: help kernel prettyprint words ;
 
 IN: help
 
 : $prettyprinting-note
-    {
+    drop {
         "This word should only be called from inside the "
         { $link with-pprint } " combinator."
     } $notes ;
@@ -233,11 +233,11 @@ HELP: . "( obj -- )"
 
 HELP: unparse "( obj -- str )"
 { $values { "obj" "an object" } { "str" "Factor source string" } }
-{ $description "Outputs a prettyprinted string representation of an object." } ;
+{ $description "Outputs a prettyprinted string representation of an object. Output is influenced by many variables; see " { $link "prettyprint-variables" } "." } ;
 
 HELP: pprint-short "( obj -- )"
 { $values { "obj" "an object" } }
-{ $description "Prettyprints an object to the default stream. This word rebinds printer control variables to enforce ``shorter'' output." } ;
+{ $description "Prettyprints an object to the default stream. This word rebinds printer control variables to enforce ``shorter'' output. See " { $link "prettyprint-variables" } "." } ;
 
 HELP: short. "( obj -- )"
 { $values { "obj" "an object" } }
@@ -245,7 +245,7 @@ HELP: short. "( obj -- )"
 
 HELP: unparse-short "( obj -- str )"
 { $values { "obj" "an object" } { "str" "Factor source string" } }
-{ $description "Outputs a prettyprinted string representation of an object. This word rebinds printer control variables to enforce ``shorter'' output." } ;
+{ $description "Outputs a prettyprinted string representation of an object. This word rebinds printer control variables to enforce ``shorter'' output. See " { $link "prettyprint-variables" } "." } ;
 
 HELP: .b "( n -- )"
 { $values { "n" "an integer" } }