]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/literals/literals-docs.factor
use radix literals
[factor.git] / basis / literals / literals-docs.factor
index 1caa4b746fa59947e0822cac7c88b0ee020a4bf9..8682da53a70bf1c6f6525a1fc01cc5e4f1b3e00c 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax kernel multiline ;
+USING: help.markup help.syntax kernel multiline sequences ;
 IN: literals
 
 HELP: $
@@ -8,23 +8,22 @@ HELP: $
 { $description "Executes " { $snippet "word" } " at parse time and adds the result(s) to the parser accumulator." }
 { $notes { $snippet "word" } "'s definition is looked up and " { $link call } "ed at parse time, so words that reference words in the current compilation unit cannot be used with " { $snippet "$" } "." }
 { $examples
-
-    { $example <"
-USING: kernel literals prettyprint ;
-IN: scratchpad
-
-CONSTANT: five 5
-{ $ five } .
-    "> "{ 5 }" }
-
-    { $example <"
-USING: kernel literals prettyprint ;
-IN: scratchpad
-
-: seven-eleven ( -- a b ) 7 11 ;
-{ $ seven-eleven } .
-    "> "{ 7 11 }" }
-
+    { $example
+        "USING: kernel literals prettyprint ;"
+        "IN: scratchpad"
+        ""
+        "CONSTANT: five 5"
+        "{ $ five } ."
+        "{ 5 }"
+    }
+    { $example
+        "USING: kernel literals prettyprint ;"
+        "IN: scratchpad"
+        ""
+        ": seven-eleven ( -- a b ) 7 11 ;"
+        "{ $ seven-eleven } ."
+        "{ 7 11 }"
+    }
 } ;
 
 HELP: $[
@@ -32,15 +31,14 @@ HELP: $[
 { $description "Calls " { $snippet "code" } " at parse time and adds the result(s) to the parser accumulator." }
 { $notes "Since " { $snippet "code" } " is " { $link call } "ed at parse time, it cannot reference any words defined in the same compilation unit." }
 { $examples
-
-    { $example <"
-USING: kernel literals math prettyprint ;
-IN: scratchpad
-
-<< CONSTANT: five 5 >>
-{ $[ five dup 1 + dup 2 + ] } .
-    "> "{ 5 6 8 }" }
-
+    { $example
+        "USING: kernel literals math prettyprint ;"
+        "IN: scratchpad"
+        ""
+        "<< CONSTANT: five 5 >>"
+        "{ $[ five dup 1 + dup 2 + ] } ."
+        "{ 5 6 8 }"
+    }
 } ;
 
 HELP: ${
@@ -48,32 +46,47 @@ HELP: ${
 { $description "Outputs an array containing the results of executing " { $snippet "code" } " at parse time." }
 { $notes { $snippet "code" } "'s definition is looked up and " { $link call } "ed at parse time, so words that reference words in the current compilation unit cannot be used with " { $snippet "$" } "." }
 { $examples
+    { $example
+        "USING: kernel literals math prettyprint ;"
+        "IN: scratchpad"
+        ""
+        "CONSTANT: five 5"
+        "CONSTANT: six 6"
+        "${ five six 7 } ."
+        "{ 5 6 7 }"
+    }
+} ;
 
-    { $example <"
-USING: kernel literals math prettyprint ;
-IN: scratchpad
+{ POSTPONE: $ POSTPONE: $[ POSTPONE: ${ } related-words
 
-CONSTANT: five 5
-CONSTANT: six 6
-${ five six 7 } .
-    "> "{ 5 6 7 }"
+HELP: flags{
+{ $values { "values" sequence } }
+{ $description "Constructs a constant flag value from a sequence of integers or words that output integers. The resulting constant is computed at parse-time, which makes this word as efficient as using a literal integer." }
+{ $examples
+    { $example
+        "USING: literals kernel prettyprint ;"
+        "IN: scratchpad"
+        "CONSTANT: x 0x1"
+        "flags{ 0x20 x 0b100 } .h"
+        "25"
     }
 } ;
 
-{ POSTPONE: $ POSTPONE: $[ POSTPONE: ${ } related-words
 
 ARTICLE: "literals" "Interpolating code results into literal values"
 "The " { $vocab-link "literals" } " vocabulary contains words to run code at parse time and insert the results into more complex literal values."
-{ $example <"
-USE: literals
-IN: scratchpad
-
-CONSTANT: five 5
-{ $ five $[ five dup 1 + dup 2 + ] } .
-    "> "{ 5 5 6 8 }" }
-{ $subsection POSTPONE: $ }
-{ $subsection POSTPONE: $[ }
-{ $subsection POSTPONE: ${ }
-;
+{ $example
+    "USING: kernel literals math prettyprint ;"
+    "IN: scratchpad"
+    ""
+    "<< CONSTANT: five 5 >>"
+    "{ $ five $[ five dup 1 + dup 2 + ] } ."
+    "{ 5 5 6 8 }"
+}
+{ $subsections
+    POSTPONE: $
+    POSTPONE: $[
+    POSTPONE: ${
+} ;
 
 ABOUT: "literals"