]> gitweb.factorcode.org Git - factor.git/commitdiff
Documentation updates
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 20 Jul 2008 06:13:36 +0000 (01:13 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 20 Jul 2008 06:13:36 +0000 (01:13 -0500)
extra/fry/fry-docs.factor
extra/help/handbook/handbook.factor

index eba2f95727d1dad6ac4650b1c1a0efe172474458..05cde62c1fa6771851b995c4f9f8d463637af384 100755 (executable)
@@ -19,10 +19,11 @@ HELP: fry
 \r
 HELP: '[\r
 { $syntax "code... ]" }\r
-{ $description "Literal fried quotation. Expands into code which takes values from the stack and substituting them in." } ;\r
+{ $description "Literal fried quotation. Expands into code which takes values from the stack and substitutes them in place of the fry specifiers " { $link , } " and " { $link @ } "." }\r
+{ $examples "See " { $link "fry.examples" } "." } ;\r
 \r
 ARTICLE: "fry.examples" "Examples of fried quotations"\r
-"Conceptually, " { $link fry } " is tricky however the general idea is easy to grasp once presented with examples."\r
+"The easiest way to understand fried quotations is to look at some examples."\r
 $nl\r
 "If a quotation does not contain any fry specifiers, then " { $link POSTPONE: '[ } " behaves just like " { $link POSTPONE: [ } ":"\r
 { $code "{ 10 20 30 } '[ . ] each" }\r
@@ -38,9 +39,10 @@ $nl
     "{ 10 20 30 } 5 [ 3 ] swap [ / ] curry compose map"\r
     "{ 10 20 30 } [ 3 5 / ] map"\r
 }\r
-"Occurrences of " { $link @ } " are simply syntax sugar for " { $snippet ", call" } ". The following three lines are equivalent:"\r
+"Occurrences of " { $link @ } " are simply syntax sugar for " { $snippet ", call" } ". The following four lines are equivalent:"\r
 { $code \r
     "{ 10 20 30 } [ sq ] '[ @ . ] each"\r
+    "{ 10 20 30 } [ sq ] [ call . ] curry each"\r
     "{ 10 20 30 } [ sq ] [ . ] compose each"\r
     "{ 10 20 30 } [ sq . ] each"\r
 }\r
@@ -50,16 +52,17 @@ $nl
     "{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry 3compose map"\r
     "{ 8 13 14 27 } [ even? dup 5 ? ] map"\r
 }\r
-"Occurrences of " { $link _ } " have the effect of enclosing all code to their left with " { $link >r } " and " { $link r> } ":"\r
+"Occurrences of " { $link _ } " have the effect of enclosing all code to their left in a quotation passed to " { $link dip } ". The following four lines are equivalent:"\r
 { $code \r
     "{ 10 20 30 } 1 '[ , _ / ] map"\r
+    "{ 10 20 30 } 1 [ [ ] curry dip / ] curry map"\r
     "{ 10 20 30 } 1 [ swap / ] curry map"\r
     "{ 10 20 30 } [ 1 swap / ] map"\r
 }\r
 "For any quotation body " { $snippet "X" } ", the following two are equivalent:"\r
 { $code\r
-    "[ >r X r> ]"\r
-    "[ X _ ]"\r
+    "[ [ X ] dip ]"\r
+    "'[ X _ ]"\r
 }\r
 "Here are some built-in combinators rewritten in terms of fried quotations:"\r
 { $table\r
@@ -73,8 +76,11 @@ $nl
 } ;\r
 \r
 ARTICLE: "fry.philosophy" "Fried quotation philosophy"\r
-"Fried quotations generalize quotation-building words such as " { $link curry } " and " { $link compose } "."\r
-$nl\r
+"Fried quotations generalize quotation-building words such as " { $link curry } " and " { $link compose } ". They can clean up code with lots of currying and composition, particularly when quotations are nested:"\r
+{ $code\r
+    "'[ [ , key? ] all? ] filter"\r
+    "[ [ key? ] curry all? ] curry filter"\r
+}\r
 "There is a mapping from fried quotations to lexical closures as defined in the " { $vocab-link "locals" } " vocabulary. Namely, a fried quotation is equivalent to a ``let'' form where each local binding is only used once, and bindings are used in the same order in which they are defined. The following two lines are equivalent:"\r
 { $code\r
     "'[ 3 , + 4 , / ]"\r
@@ -87,7 +93,7 @@ $nl
 } ;\r
 \r
 ARTICLE: "fry.limitations" "Fried quotation limitations"\r
-"As with " { $vocab-link "locals" } ", fried quotations cannot contain " { $link >r } " and " { $link r> } "." ;\r
+"As with " { $vocab-link "locals" } ", fried quotations cannot contain " { $link >r } " and " { $link r> } ". This is not a real limitation in practice, since " { $link dip } " can be used instead." ;\r
 \r
 ARTICLE: "fry" "Fried quotations"\r
 "A " { $emphasis "fried quotation" } " differs from a literal quotation in that when it is evaluated, instead of just pushing itself on the stack, it consumes zero or more stack values and inserts them into the quotation."\r
index 9ffd2419159aefcd74d530ad2a15049bdcf0fef8..fc0d00e94d9899417c90551bb69d2e330219f9d8 100755 (executable)
@@ -137,7 +137,7 @@ ARTICLE: "collections" "Collections"
 { $subsection "heaps" }
 { $subsection "graphs" }
 { $subsection "buffers" }
-"There are many other collections in " { $snippet "extra/" } ", such as " { $vocab-link "disjoint-set" } ", " { $vocab-link "persistent-vectors" } ", and " { $vocab-link "tuple-arrays" } "." ;
+"There are many other collections in " { $snippet "extra/" } ", such as " { $vocab-link "disjoint-sets" } ", " { $vocab-link "persistent-vectors" } ", and " { $vocab-link "tuple-arrays" } "." ;
 
 USING: io.encodings.utf8 io.encodings.utf16 io.encodings.binary io.encodings.ascii io.files ;